Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker Architecture

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

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.

Common commands:

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:

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:

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:

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:

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:

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:

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:

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:

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:

Create and mount a volume:

docker volume create my_volume

docker run -d -v my_volume:/data ubuntu