Skip to content

Docker Engine

Docker Engine, often referred to as Docker, is an open-source technology that provides the core runtime for building, running, and managing containers. It acts as a client-server application with three core components:

  • The Docker Daemon (dockerd)
    • A long-running server process responsible for managing Docker containers, images, networks, and volumes.
  • The Command-Line Interface (CLI) Client (docker)
    • The primary way for users to send commands and instructions to the Docker daemon (dockerd), which performs the actual operations.
  • The REST API
    • A programmatic interface for interacting with the Docker daemon. Even the Docker CLI itself uses these REST APIs under the hood to communicate with the daemon.

Docker Engine requires a Linux Kernel and so it can run natively only on Linux but not Windows/MacOS. It is ideal for production servers and headless environments (e.g., cloud instances), as it often requires manual installation and configuration.

Installation

The Docker Engine installation instructions for various Linux platforms can be found in the official docs here.

Post-installation steps

Manage Docker as a non-root user

  • Create docker group (This group should already exist):
sh
sudo groupadd docker
  • Add your current user to the docker group:
sh
sudo usermod -aG docker $USER
  • Run the following command to activate the changes to groups:

If you're running Linux in a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.

sh
newgrp docker
  • Verify that you can run docker commands without sudo:
sh
docker run hello-world

Configure Docker to start on boot with systemd

On Debian and Ubuntu, the Docker service starts on boot by default. To automatically start Docker and containerd on boot for other Linux distributions using systemd, run the following commands:

sh
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To stop this behavior, use disable instead:

sh
sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Configure default logging driver

Docker uses logging drivers to collect and manage container logs. By default, it uses the json-file driver, which stores logs as JSON files on the host. Over time, these files can grow large and consume disk space.

To prevent this, you can:

  • Enable log rotation for json-file to limit log size.
    • To enable log rotation, update the Docker configuration file, found at /etc/docker/daemon.json on Linux, to set the max-size and max-file options:
json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
  • Use the local logging driver, which has built-in log rotation (100MB limit per container).
    • To do this, update /etc/docker/daemon.json using:
json
{
  "log-driver": "local",
  "log-opts": {
    "max-size": "10m"
  }
}
  • Send logs to a remote logging system for centralized storage and management.