Docker is an open source platform to develop, ship and run an application in an isolated way using docker containers. Container is an unit of software that packages all dependencies such as binaries and libraries required to run an application.
Containers are not new technologies, since from 1979 used in UNIX system. The below article give a detailed info about container evolution from dzone.
The Evolution of Linux Containers and Their Future
Docker containers isolate from each other but share the same Linux kernel system. This uses the kernel namespaces and cgroups to manage application. Docker containers can deployed in separate and managed as usual application.
Docker containers vs Virtual Machines
The Docker also use virtualization as Virtual Machines. But it uses OS level virtualization, whereas VM uses hardware level virtualization. Docker shares the Operating system kernel, VM shares the hardware. This makes docker more efficient than VM. Consider the following picture which illustrates the difference between Docker and VM.
In VM architecture, it uses the Hypervisor to manage the Guest OS on it. Each Guest OS has different binaries and libraries for running software applications. In docker, it shares the Linux kernel to run all applications with its own dependencies.
These dependencies packaged as image called docker images. Docker images deployed as containers to run the application in an isolated environment. These containers are run on docker engine.
Images are simple templates that instructs to create the containers. Each image even built from another images itself. These images can be build using the dockerfile. dockerfile is a file which instructs to build an image using other images and dependencies. Even the syntax for writing the dockerfile is simple language. Each line in the dockerfile creates a layer to run a container. The registries such as docker registry, cloud registries include docker hub, Amazon ECR, Azure container registry.
Container are the runnable instances using the docker images. It packages all the bins and libraries needed to run the application in an isolated environment. Docker CLI and Docker API can used to create, delete, start, stop containers using the Docker daemon. Each container has its own networks, storage, and configs. Container can connect to another container using its networks . When a container deleted, the storage in the container also removed. Here we can use the persistent storage for storing the data instead of containers.
dockerd) uses Docker API manages the all docker objects in the docker environment. These objects are containers, images, storage, networks. The docker daemon communicates with other daemons for container management and network communication.
docker) is the interactive way we can execute the API to manage docker system. To manage the docker daemon the docker API called using docker command.
Docker images are stored in the registries. Docker hub is a public registry, we can create and push the image in this docker hub.
docker pull, docker push commands used to pull and push docker images from the registry. Cloud technologies also provide registries such as Amazon ECR by AWS, Azure container registry by Azure cloud.
Docker can be installed natively in Linux and Mac OS since it uses linux namespaces and cgroups for working. In windows, docker can be installed with some dependencies. Docker desktop, a GUI based docker tool is available for Windows and Mac OS
The following link give the documentation for installing docker in Mac OS, Windows and Linux distros.
Running our first docker container
First, check the docker is installed on your system using following command
$ docker --version Docker version 19.03.8, build afacb8b7f0
Now, we run our first container
hello-world image. If image is not present in our local system, it pulls those image from docker hub and runs it.
$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
To list the container running in the system use
$ docker ps --all CONTAINER ID IMAGE COMMAND CREATED STATUS 54f4984ed6a8 hello-world "/hello" 20 seconds ago Exited (0) 19 seconds ago
To list the images pulled use
$ docker image ls
The next post will be about building a docker image.
For docker reference refer this docs -> go.
For my programming article refer this -> go.
If any suggestions or queries please comment it.
1,281 total views