Docker Architecture

From the picture below, we can see that Docker uses a Client-Server Architecture. Similar to my final year projects, haha. But this time, it’s for containers. The Docker daemon (dockerd) handles the hard part of running and distributing containers.

alt text

Docker Daemon (dockerd)

Docker Client

Docker Registry

Docker Objects

The relationship between images ( Image) and containers ( ) is like that between and Containerin object-oriented programming - reference

This mainly refers to the relationship between images and containers is like . Why? Because images are static definitions, and containers are running instances of those images. Containers can be created, started, stopped, deleted, paused, etc. But it’s not limited to that.

Docker Images

Container

Both images and containers use layered storage. This means if a container is deleted or destroyed, everything, including its storage layer, is lost. This layer should remain stateless.

This is different from Docker volumes, which run independently of the container. Therefore, after using a data volume, the data will not be lost even if the container is deleted or restarted.

A container is usually defined by an image.


Example:

Running Ubuntu and interacting with it via the CLI. This example is taken from the Docker Docs.

docker run -i -t ubuntu /bin/bash

If you don’t have the ubuntu image locally, Docker pulls it from your configured registry, as though you had run docker pull ubuntu manually.

  1. Docker creates a new container, as though you had run a docker container create command manually.

  2. Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem.

  3. Docker creates a network interface to connect the container to the default network, since you didn’t specify any networking options. This includes assigning an IP address to the container. By default, containers can connect to external networks using the host machine’s network connection.

  4. Docker starts the container and executes /bin/bash. Because the container is running interactively and attached to your terminal (due to the -i and -t flags), you can provide input using your keyboard while Docker logs the output to your terminal.

  5. When you run exit to terminate the /bin/bash command, the container stops but isn’t removed. You can start it again or remove it.