Docker Architecture
Docker architecture is based on a client-server model, which includes multiple key components to ensure efficient building, management, and operation of containerized applications.
The architecture design of Docker enables developers to easily package their applications with all dependencies in a portable container and run them consistently across different environments.
Docker uses a client-server (C/S) architecture pattern and uses remote APIs to manage and create Docker containers.
Docker containers are created from Docker images.
The relationship between containers and images is similar to objects and classes in object-oriented programming.
| Docker | Object-Oriented |
| --- | --- |
| Container | Object |
| Image | Class |
### Docker Architecture Diagram
!(#)
### Docker Architecture Workflow
* **Build Image**: Create images using `Dockerfile`.
* **Push Image to Registry**: Upload images to Docker Hub or private registry.
* **Pull Image**: Pull images from registry using `docker pull`.
* **Run Container**: Create and start containers using images.
* **Manage Container**: Use Docker client commands to manage running containers (e.g., view logs, stop containers, view resource usage, etc.).
* **Network and Storage**: Containers communicate through Docker networks, and data is persisted using Docker volumes or bind mounts.
Next, let's dive into Docker's core components and how they work.
### 1. **Docker Client**
The Docker Client is the command-line interface (CLI) for users to 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, viewing container status, etc.
* **Interaction Method**: Docker client communicates with Docker daemon through REST API or Unix socket. The commonly used command-line tool is `docker`, through which users can issue various Docker operation commands.
#### Common Commands:
* `docker run`: Run a container.
* `docker ps`: List running containers.
* `docker build`: Build a Docker image.
* `docker exec`: Execute commands in a container.
### 2. **Docker Daemon**
The Docker daemon (typically `dockerd`) is the core of the Docker architecture, responsible for managing container lifecycle, building images, distributing images, and other tasks.
The daemon typically runs as a background process, waiting for API requests from Docker clients.
**Functions**:
* Start and stop containers.
* Build, pull, and push images.
* Manage container network and storage.
* Start, stop, view container logs, etc.
* Communicate with Docker registry to manage image storage and distribution.
The Docker daemon listens for requests from Docker clients and executes these requests through the Docker API. The daemon is responsible for managing Docker objects such as containers and images, and based on request parameters, starts containers, deletes containers, modifies container configurations, etc.
Start Docker daemon (usually auto-started):
sudo systemctl start docker
### 3. **Docker Engine API**
The Docker Engine API is a RESTful interface provided by Docker, allowing external clients to communicate with the Docker daemon. Through this API, users can perform various operations such as starting containers, building images, viewing container status, etc. The API provides HTTP request interfaces and supports cross-platform calls.
**Functions**:
* Send HTTP requests to Docker daemon to achieve container and image management.
* Provide RESTful interface, allowing programmatic interaction with Docker.
You can access the Docker Engine API using `curl` or other HTTP clients. For example, query the current Docker daemon version:
curl --unix-socket /var/run/docker.sock http://localhost/version
### 4. **Docker Containers**
Containers are the execution environment of Docker. They are lightweight, independent, and executable software packages. Containers are started from Docker images and contain everything needed to run an applicationβfrom OS libraries to application code. Containers share the OS kernel with other containers and the host when running, but the file systems and processes between containers are isolated.
**Functions**:
* Provide an independent runtime environment to ensure applications behave consistently across different environments.
* Containers are temporary and are usually destroyed after task completion.
The container lifecycle is managed by the Docker daemon. Containers can run anywhere because they don't depend on the underlying OS configurationβall runtime dependencies are encapsulated in the image.
Start a container
YouTip