Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a set of containers.
1. Docker Engine
The Docker Engine is the heart of the Docker system. It's a client-server application with three major components:
Server: A type of long-running program called a daemon process (the
dockerd
command).REST API: Specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
CLI (Command-Line Interface): A command-line tool that allows users to interact with Docker directly, using commands.
The Docker CLI uses the Docker REST API to interact with the Docker daemon, allowing users to operate Docker without directly interfacing with the daemon.
2. Docker Images
Images: Docker images are read-only templates used to build containers. They are the building blocks of the Docker world.
Dockerfile: To build an image, Docker uses instructions written in a Dockerfile. A Dockerfile is a text file that contains all the commands a user could call on the command line to assemble an image.
Docker Hub/Registry: Docker stores the images you build in registries. Docker Hub is a public registry service that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry using the Docker Registry product.
3. Docker Containers
Containers are lightweight and standalone executable software packages that include everything needed to run a piece of software, including the code, runtime, system tools, and system libraries. Docker containers are spun up from Docker images. Once you've created a container from an image, you can manage it (start, stop, remove, etc.) using the Docker CLI or API.
4. Docker Compose
Docker Compose is a tool for defining and managing multi-container Docker applications. For such applications, instead of starting each container separately, you can use a docker-compose.yml
file to define all services, networks, and volumes, then bring up the entire stack with a single command (docker-compose up
).
5. Docker Swarm
Docker Swarm is the native clustering and orchestration tool for Docker. It turns a group of Docker hosts into a single, virtual host. Docker Swarm specializes in maintaining the desired state of services, which is beneficial for scaling out services and rolling updates.
6. Docker Services and Stack
With Docker 1.12 and higher, the concept of services was introduced. A service is a description of a task to execute. When a service is scaled out, Swarm ensures the correct number of tasks are maintained, adjusting as necessary.
A stack in Docker is a collection of services that are deployed together from a docker-compose.yml
file. A single stack is capable of defining and coordinating the functionality of an entire application (consisting of multiple microservices).
Networking and Storage:
Networking: Docker uses host-private networking by default, so containers can communicate with each other using IP addresses they get from a private IP range. Docker also supports various networking drivers to customize container networking as per requirements.
Volumes: These are used to persist data generated by and used by Docker containers. Docker volumes are superior to bind mounts (which directly map host paths into containers) as they are managed by Docker and can be more safely shared and backed-up.
The success of Docker is due to its architecture, which is both modular and extensible. It separates major functionalities (like Docker Compose and Docker Swarm) into separate tools, allowing users to pick and choose based on their specific requirements, and integrates these tools smoothly when required.