When we started learning about Docker, we touched upon Docker ecosystem and some related components. Now we should dig a little bit deeper.
Docker follows client-server architecture. To use Docker, we need to have 2 major components installed. Those are Docker daemon(server) and Docker client(client). We can install them in a single system or separate systems. We have another component called registry, that hosts Docker images. Lets understand each of these
Docker daemon – At the heart of Docker, we have a process responsible for managing all Docker objects(images, containers, networks, volumes)called Docker daemon(dockerd).
Registry – Registry is like a repository that hosts all docker images. Docker hub is an example of registry that holds thousands of public as well as private docker images. We can have other Container registry as well, then we need to configure Docker server accordingly.
Docker client – Docker client(docker) is a tool, mostly installed in local system to communicate with Docker daemon and send instructions to perform different activities. Some of the activities are like pulling images, run container, and lots more. Docker client communicates with Docker daemon via REST API call.
How we run a Docker container?
- Mostly it starts with pulling an image or running an image. To do that, we use docker pull or docker run command through Docker client
- Docker daemon listens to the API requests from client, and looks for the image in Server images list. Otherwise it pulls the image from Docker registry
- In case of docker pull, it only pulls the image from registry and stores in server images. But in case of docker run, after pulling the image, it runs the image
- A running docker image is called a Container. Docker demon is responsible for running the Container and managing related objects like networks and volumes
- We can also build a new Docker Image using docker build command based on configurations in Dcokerfile. We can run the Image as Container and push the Image to Registry as well.
Docker Desktop – Docker Desktop is an optional UI based tool, that can be installed in local system for building and running Docker Images. It has Docker client, Docker daemon, and some more components like Docker Compose, Kubernetes etc. as part of this tool. This is kind of one stop shop for Development using Docker.
Lets understand about different Docker objects
Images – Docker Images are the physical files that contains all the details related to application, packages, Docker build and configuration etc. Docker images are built in multiple layers, that makes them efficient during sync up between registry and host images. Mostly, for building docker images, we use a minimal Linux base layer.
Container – Container is a running instance of a Docker Image, managed by Docker daemon. Using Docker client or Docker Desktop, we can interact with Docker daemon to create, start, stop, rerun Container instances. We can interact with a Container, run shell scripts, configure network and access applications running inside the it. Container exists only when it’s running. So if we create any file in a running Container, it wipes out after it’s stopped.
Network – Docker Container runs in isolation, but to interact with each other or to interact externally, we need to configure network. When we create a Container, a default bridge network is attached to it. But we can configure and create different types of networks and assign with the Container.
Volume – Container is temporary, but we might need to store files/data for the running applications inside containers. For example, if we want to run a database or a web application needs to store images inside a container, we need to configure and use Volume. Its persistent storage solution for Docker and its managed by Docker.
We have understood how Dockers works. Let’s try running our first Docker Container.