What is Docker
Docker is a containerization platform for developing, packaging, shipping and running applications. It gives the ability to run an application in an isolated environment called a container.
A developer can define all the requirements in Dockerfile which is then used to build and run images that defines a docker container
This ensures that our application can run in environment, regardless of the operating system. (Basically your excuse of it works on my machine won't work ¯\_(ツ)_/¯
)
Why use docker and its use cases?
Using docker can help you scale your applications easily. It gives you control over your application. It helps in the proper utilization of resources.
Docker can be used in various scenarios like
- Application in devops.
- Improvement in software testing.
- Creation of microservices architecture.
- Multi environment architecture
Architecture of Docker & it's working
Docker follows client-server architecture. The docker client interacts with the daemon with help of REST API, which manages the docker containers.
Docker client and daemon can run on the same system, or they can even remotely connected.
Another client is docker compose, which we use when we have set of containers.
Docker Client - docker
The docker client (docker
) is the primary method of interaction used by users. When we send commands docker run
, docker pull
, etc, it sends requests to docker daemon(dockerd
) which carries them out.
One docker client can connect with multiple daemons.
Docker Daemon - dockerd
dockerd
listens for API requests and manages Docker objects such as images, containers, networks, and volumes.
Docker Images
Docker images are like a blueprint which are used to build containers. Most often, one image is based on another image, and these images are read only. Hence when we want a custom things, we build upon these base images.
We can use predefined images from the Docker Registry or we build and add more layers upon those images to make our own custom images. For that we can use a Dockerfile
.
Each instruction in the Dockerfile
makes a layer in the image, and when we rebuild or make changes in the Dockerfile
, only those layers in the images will be rebuilt which we modified. This feature of docker makes it lightweight, small and fast.
What are layers in images?
Container images are composed of various read only layers. Each of these layers represent a set of filesystem changes made during the image build process. These changes can include adding, modifying, or deleting files and directories. And each layer corresponds to a specific instruction.
Docker Containers
A container is a runnable instance of an image. We can start, stop, run, move or delete a container using the docker API or cli. By default these containers are well isolated from other containers and its host machine.
For example if I could explain in terms of OOPs(Object Oriented Programming) - then a Docker image
would be similar to a class
and a Docker container
would be instance of the that class, i.e., an object
of that class.
Docker Registry
A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker looks for images on Docker Hub by default. You can even run your own private registry.
It's like Github but for images, whereas Github is for code.
How are Containers different from Virtual Machines?
Virtual Machines are essentially self contained computer within our physical computer. It has its own resources, hardwares, and network interfaces, all of which is created with the help of Hypervisor
Let's have a brief comparison between containers and virtual machines:
Docker Container | Virtual Machine |
---|---|
A container is a isolated process with all files need to run. | VM is an OS with its own kernel, hardware drivers, programs, applications. |
Lower disk usage, faster, and low impact on OS | High impact on OS, slower and higher disk usage |
Encapsulate a single application | Encapsulate a whole machine |
Often containers and VMs are used together, e.g., In cloud environment, the machines are VMs and we can run multiple containers in it thus utilizing the resources and reducing costs.
That's all for now!! In the next post I will try to cover about the various commands used for the interaction with docker-cli
and we'll also deep dive into OCI and OCI runtime.
Top comments (0)