Docker Architecture
Docker's architecture is based on a client-server model and includes several key components that ensure the efficient building, management, and running of containerized applications.
Docker's architectural design allows developers to easily package an application together with all of its dependencies into a portable container and run it consistently in different environments.
Docker uses a client-server (C/S) architecture and manages and creates Docker containers through a remote API.
Docker containers are created from Docker images.
The relationship between containers and images is similar to the relationship between objects and classes in object-oriented programming.
| Docker | Object-oriented |
|---|---|
| Containers | object |
| Images | class |
Docker Architecture Diagram

The Docker Architecture Workflow
- Building Images: When using
DockerfileCreate an image. - Pushing Images to a Registry: Upload the image to Docker Hub or a private registry.
- Pulling Images: Through
docker pullPull an image from a registry. - Running Containers: Create and start a container from an image.
- Managing Containers: Use Docker client commands to manage running containers (for example, viewing logs, stopping containers, checking resource usage, and so on).
- Networking and Storage: Containers communicate with each other over Docker networks, and data is persisted through Docker volumes or bind mounts.
Next, let us take a deeper look at Docker's core components and how they work.
1、Docker Client
The Docker client is the command-line interface (CLI) through which users interact with the Docker daemon. It is the primary way users interact with the Docker system: users issue commands through the Docker CLI, which are sent to the Docker daemon for execution.
- Function: Allows users to communicate with the Docker daemon using commands, such as creating containers, building images, and viewing container status.
- Interaction method: The Docker client communicates with the Docker daemon through a REST API or a Unix socket. The commonly used command-line tool is
docker, through which users can issue various Docker commands.
Common commands:
docker run: Run a container.docker ps: List running containers.docker build: Build a Docker image.docker exec: Execute a command inside a container.
2、Docker Daemon
The Docker daemon (usually dockerd) is the core of the Docker architecture, responsible for managing the container lifecycle, building images, distributing images, and other tasks.
The daemon typically runs as a background process, waiting for API requests from the Docker client.
Function:
- Start and stop containers.
- Build, pull, and push images.
- Manage container networking and storage.
- Start, stop, and view container logs, and so on.
- Communicate with Docker registries to manage image storage and distribution.
The Docker daemon listens for requests from Docker clients and executes them through the Docker API. The daemon manages Docker objects such as containers and images, and starts, removes, or reconfigures containers according to the parameters in the requests.
Start the Docker daemon (usually started automatically):
sudo systemctl start docker
3、Docker Engine API
The Docker Engine API is a RESTful interface provided by Docker that allows external clients to communicate with the Docker daemon. Through this API, users can perform various operations such as starting containers, building images, and viewing container status. The API provides an HTTP request interface and supports cross-platform calls.
Function:
- Send HTTP requests to the Docker daemon to manage containers and images.
- Provide a RESTful interface that allows programmatic interaction with Docker.
can be used via curl or another HTTP client to access the Docker Engine API. For example, to query the version of the current Docker daemon:
curl --unix-socket /var/run/docker.sock http://localhost/version
4、Docker Containers
A container is Docker's execution environment: a lightweight, standalone, and executable software package. A container is started from a Docker image and contains everything needed to run an application, from operating system libraries to application code. At runtime, containers share the operating system kernel with other containers and the host, but their filesystems and processes are isolated from one another.
Function:
- Provide an isolated runtime environment, ensuring consistent behavior of applications across different environments.
- Containers are ephemeral and are usually destroyed after the task is complete.
A container's lifecycle is managed by the Docker daemon. Containers can run anywhere because they do not depend on the underlying operating system configuration; all runtime dependencies are packaged in the image.
Start a container:
docker run -d ubuntu
5、Docker Images
A Docker image is a read-only template for a container. Each image contains the operating system, runtime, libraries, environment variables, and application code needed to run an application. Images are static, and users can start containers from them.
Function:
- Images are the basis for building containers; every container instance is created from an image.
- Images are read-only. When different containers use the same image, their filesystem layers are independent.
Docker images can be docker pull pulled from Docker Hub or a private registry, or docker build built from a Dockerfile.
Pull the Ubuntu image:
docker pull ubuntu
6. Docker Registries
A Docker registry is where Docker images are stored; the most widely used public registry is Docker HubDocker Hub. Users can download images from Docker Hub and upload their own images to share with others. Besides public registries, users can also deploy their own private Docker registry to manage images within an organization.
Function:
- Store Docker images.
- Provide image upload and download capabilities.
Docker Hub offers a large number of official and community-maintained images, such as Ubuntu, Nginx, and MySQL.
Push an image to Docker Hub:
docker push /
7、Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, users can use a docker-compose.yml configuration file to define multiple containers (services) and start them all with a single command. Docker Compose is mainly used for developing, testing, and deploying multi-container applications.
Function:
- Define and run applications composed of multiple containers.
- Configure an application's services, networks, and volumes through a YAML file.
Create a simple docker-compose.yml file to configure an application with a web service and a database service:
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
Start all services defined by Compose:
docker-compose up
8、Docker Swarm
Docker Swarm is Docker's clustering and scheduling tool. It allows multiple Docker hosts (nodes) to be organized into a cluster, and containers to be scheduled and managed through the Swarm cluster management tools. Swarm supports load balancing, high availability, and automatic scaling of containers.
Function:
- Manage multi-node Docker clusters.
- Manage the deployment and scaling of containers through a scheduler.
Initialize a Swarm cluster:
docker swarm init
9、Docker Networks
Docker networking allows containers to communicate with one another and connect to the outside world. Docker provides several network modes to meet different needs, such as bridge networks (default),host networks and overlay networks, and so on.
Function:
- Manage network communication between containers.
- Support different network modes to suit the needs of different scenarios.
Create a custom network and connect containers to it:
docker network create my_network
docker run -d --network my_network ubuntu
10. Docker Volumes
A Docker volume is a data persistence mechanism that allows data to be shared between containers and exists independently of the container lifecycle. Unlike a container filesystem, the contents of a volume are not lost when the container is destroyed, making volumes suitable for applications that need persistent storage, such as databases.
Function:
- Allow data to be shared between containers.
- Ensure data persistence independently of the container lifecycle.
Create and mount a volume:
docker volume create my_volume
docker run -d -v my_volume:/data ubuntu