Skip to content

Docker - Configuring

This chapter covers basic configuration aspects of the Docker Engine, including managing the service and setting common options.

Managing the Docker Service (Linux with systemd)

Section titled “Managing the Docker Service (Linux with systemd)”

On most modern Linux distributions using systemd, you manage the Docker service (daemon) using systemctl commands. These typically require sudo privileges.

sudo systemctl stop docker

This command stops the Docker daemon process.

sudo systemctl start docker

This command starts the Docker daemon process.

sudo systemctl restart docker

This command stops and then starts the Docker daemon, useful for applying configuration changes.

sudo systemctl status docker

Shows whether the service is active, recent logs, and other status information.

sudo systemctl enable docker

Configures the system to automatically start the Docker service when the machine boots up.

sudo systemctl disable docker

Prevents the Docker service from starting automatically on boot.

Configuring Docker Daemon Options (daemon.json)

Section titled “Configuring Docker Daemon Options (daemon.json)”

The recommended way to configure the Docker daemon is by creating or modifying a JSON file located at /etc/docker/daemon.json on Linux. This file allows you to customize various aspects of the Docker Engine’s behavior.

If the file doesn’t exist, create it. Remember to restart the Docker service (sudo systemctl restart docker) after making changes.

{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2",
"debug": false,
"data-root": "/var/lib/docker-custom"
}

Explanation of example options:

  • log-driver: Sets the default logging driver for containers (e.g., json-file, journald, syslog).
  • log-opts: Provides options for the chosen log driver (here, setting max log file size and number of files for json-file).
  • storage-driver: Specifies the storage driver Docker should use (e.g., overlay2). Usually best left as default unless you have specific needs.
  • debug: Enables debug-level logging for the daemon (set to true for troubleshooting, false for normal operation).
  • data-root: Changes the directory where Docker stores its data (images, containers, volumes). Use with caution.

Many other options are available. Refer to the official Docker documentation for a complete list:

https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file

On Windows and macOS, Docker Desktop provides a graphical interface for managing common settings (resource limits, Kubernetes integration, file sharing, etc.). Access these via the Docker icon in the system tray/menu bar -> Settings/Preferences.