Sign up to get Free Ebooks...

I hope you enjoy reading this article. If you are looking for such article ,Click here


Docker Explained – An Introductory Guide To Docker.

  • Home
  • /
  • Blog
  • /
  • Docker Explained – An Introductory Guide To Docker.
cloud scoop

Docker has gained immense popularity in this fast growing IT world. Organizations are continuously adopting it in their production environment.

In this blog, the following concepts will be covered:

  • what is docker?
  • Components of docker.
  • Advantages and disadvantages of docker.
  • Dockerfile and its creation.
  • Docker volume.
  • some important commands in docker.

What is docker?

Docker was first release in March 2013. It is developed by Solomen Hykes and Sebastian Pahl. Docker is a set of platform as a service that uses O.S level virtualization whereas VMware uses hardware level virtualization.

Docker is an open-source centralised platform designed to create, deploy and run application. Docker uses container on the host OS to run application . It allows applications to use the same linux kernel as a system on the computer, rather than creating a whole virtual os. We can install docker on any O.S but docker engine runs natively on linux distribution. Docker is wriiten in ‘go’ language. Docker is a tool that performs O.S level vitualization , also known as containerization.

Components of docker.

Docker Daemon – Docker daemon is responsible for running containers to manage docker services. It runs on the host O.S. Docker daemon can communicate with other daemons.

Docker Client – Docker users can interact with docker daemon through a client. Docker client uses commands and Rest API to communicate with the docker daemon. When a client runs any server command on the docker client terminal, the client terminal sends these docker commands to the docker daemon. It is possible for docker client to commicate with more than one daemon.

Docker Host – Docker host is used to provide an environment to execute and run applications . It contains the docker daemon, images, container, networks and storage.

Docker Container – Docker container hold that entire packages that is needed to run the application. Container is like a virtual machine. Images becomes Container when they run on docker engine.

Ref: Docker official

Docker images – Docker images are the read-only binary templates used to create docker containers. You can use  docker run  to run the image and create a container.

Docker images can be created in following ways:

  1. Create image from docker file.
  2. Create image from existing docker containers.
  3. Take image from dockerhub

Docker Hub/Registry – Docker Registry manages and stores the docker images. There are two types of registries in the docker.

1. Public Registry – Also known as docker hub.

2. Private Registry – It is use to share images within the enterprise.

Advantages and disadvantages of docker.

Advantages:

  • Continuous Integration Efficiency
  • Docker enables you to build a container image and use that same image across every step of the deployment process.
  • No pre-allocation of RAM
  • It can run on physical H/W / virtual H/W or on cloud.
  • It takes very less time to create container .
  • You can re-use the image

Disadvantages:

  • Docker is not good solution for application that requires rich GUI.
  • Docker does not provide cross-platform compatibility means if an application is designed to run in docker container on Windows, then it can’t run on linux or vice-versa
  • No solution for data recovery and backup.

Dockerfile

Dockerfile is basically a text file. It contains a set of instructions. So, Docker can build images automatically by reading the instructions from a Dockerfile. You can use  docker build  to create an automated build to execute several command-line instructions in succession.

Dockerfile components.

FROM - For base image. This command must be on top of the dockerfile.
RUN - To execute commands. it will create a layer in image.
MAINTAINER - Author/Owner/Description
COPY - Copy files from local system (docker VM). We need to provide source destination. (We cannot download file from internet and any remote repo)
ADD - Similar to copy , but it providesa feature to download files from internet. 
EXPOSE - To expose ports such as port 8080 for Tomcat , port 80 for ngnix etc
WORKDIR - To set working directory for a container. 
CMD - Execute commands but during container creation.
ENTRYPOINT - Similar to CMD, but has higher priority over CMD. First commands will be executed by ENTRYPOINT only.
ENV - Environment variables.
FROM ubuntu
WORKDIR /tmp
RUN echo "HELLO WOLRD! " >  /tmp/ testfile
COPY testfile1/tmp
ADD test.tar.gz/tmp

Docker Volume

Docker volume is simply a directory inside our container. Firstly, we have to declare the directory as a volume and then we can share the volume. Even if we stop the container, still we can access the volume. Volume will not be included when you update an image.

Volume can only be created during the container creation and can’t be created from existing container. You can share one volume across any number of containers.

Volumes can be mapped in two ways:

– container to container

– Host to container


Some important commands in docker.

To see all images present in your local machine.

docker images

To search images in docker hub.

docker search <image name>

To download images from docker hub to local machine.

docker pull <image name>

To run and give name to container.

docker run -it --name <container name> <image name> /bin/bash

To start container

docker start <container name>

To go inside container.

docker attach <container name>

To see all containers.

docker ps -a

To see only running containers.

docker ps

To delete container.

docker rm <container name>

To stop all running containers.

docker stop $(docker ps -a -q)

To delete all stopped containers.

docker rm $(docker ps -a -q)

To delete all images.

docker rmi -f $(docker images -q)



November 11, 2024

November 11, 2024

November 11, 2024

June 19, 2023

May 31, 2023

May 9, 2023

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>