Docker - Configuring
Docker - Configuring the Engine
Section titled “Docker - Configuring the Engine”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.
Stopping the Docker Service
Section titled “Stopping the Docker Service”sudo systemctl stop dockerThis command stops the Docker daemon process.
Starting the Docker Service
Section titled “Starting the Docker Service”sudo systemctl start dockerThis command starts the Docker daemon process.
Restarting the Docker Service
Section titled “Restarting the Docker Service”sudo systemctl restart dockerThis command stops and then starts the Docker daemon, useful for applying configuration changes.
Checking the Service Status
Section titled “Checking the Service Status”sudo systemctl status dockerShows whether the service is active, recent logs, and other status information.
Enabling Docker on Boot
Section titled “Enabling Docker on Boot”sudo systemctl enable dockerConfigures the system to automatically start the Docker service when the machine boots up.
Disabling Docker on Boot
Section titled “Disabling Docker on Boot”sudo systemctl disable dockerPrevents 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.
Example daemon.json:
Section titled “Example daemon.json:”{ "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 forjson-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 totruefor troubleshooting,falsefor 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
Docker Desktop Configuration
Section titled “Docker Desktop Configuration”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.