Docker daemon.json generator

Choose the settings and get a daemon.json that dockerd accepts, an explanation of every key and the commands that put it in place safely. Everything is written in your browser.

json-file is Docker's default and what docker logs reads; local is more compact. Both rotate with the two settings beside it.
A number with k, m or g. Docker's default is no limit.
Rotated files kept per container, the current one included.
One pool per line: base and network size, for example 10.200.0.0/16 24. Empty keeps Docker's built-in pools (172.17–172.31 and 192.168).
The bridge's own address with its prefix, for example 10.199.0.1/24. Empty: Docker picks it.
Containers keep running while the daemon restarts or upgrades. It takes effect after the first restart with it.
Not set lets Docker choose, which is overlay2 on current systems. Set it only to pin that default.
Address and port for Prometheus metrics, for example 127.0.0.1:9323. Empty: off.
One https:// URL per line. Docker Hub pulls try the mirrors first and fall back to Docker Hub.
One range per line, for example 192.168.1.0/24. Only used to warn about overlaps; they stay on this page.

Your daemon.json

daemon.json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Apply it

  1. Back up the current file, if there is one.
  2. Install the new file with the right owner and mode.
  3. Validate it with dockerd --validate before restarting: a file dockerd refuses would stop Docker from starting.
  4. Restart Docker. Running containers stop and start again unless live-restore was already on before this restart.
  5. Check that the settings are in effect. Log and network settings apply to containers and networks created after the restart; recreate the others (docker compose up -d --force-recreate).
apply-commands.txt
[ ! -f /etc/docker/daemon.json ] || sudo cp -p /etc/docker/daemon.json /etc/docker/daemon.json.bak
sudo install -m 0644 -D daemon.json /etc/docker/daemon.json
sudo dockerd --validate --config-file /etc/docker/daemon.json
sudo systemctl restart docker
docker info --format '{{.LoggingDriver}} {{.Driver}} live-restore={{.LiveRestoreEnabled}}'

To go back: sudo mv /etc/docker/daemon.json.bak /etc/docker/daemon.json && sudo systemctl restart docker.

Not sure which ranges collide? Check your LAN and VPN against Docker's networks

What it does

It writes /etc/docker/daemon.json, the file dockerd reads at start, for a Linux server: log rotation so container logs cannot fill the disk, address pools that keep Docker's networks away from your LAN and VPN, live-restore, the storage driver, registry mirrors and the metrics endpoint. Each key is explained and the page gives the commands that apply it safely.

How it works

  1. The file is written in your browser by @anaroq/linux, the engine behind our other Linux tools. Keys you do not set are left out, so Docker keeps its own default for them.
  2. A value dockerd would refuse, such as a pool that is not a range, overlapping pools or a mirror with a path, is refused next to the field instead of being written.
  3. The same files pass dockerd --validate in our tests, which loads a configuration exactly as the daemon does at start.

What each key does

log-driver and log-opts
Where container output goes, and when its file is rotated: max-size per file, max-file files kept. Without them json-file logs grow until the disk is full.
storage-driver
How image layers are stored. overlay2 is Docker's documented default; changing it on a server that has data hides existing images and containers.
default-address-pools
The ranges Docker carves networks from: base is the pool, size the prefix of each network. They replace the built-in 172.17–172.31 and 192.168 pools.
bip
The address of the default docker0 bridge with its prefix. Keeping it outside the pools leaves the pools whole for your networks.
registry-mirrors
Pull-through caches for Docker Hub images. Docker tries them in order and falls back to Docker Hub.
live-restore
Containers keep running while dockerd is down for a restart or an upgrade. Not compatible with Swarm mode.
metrics-addr
Serves Prometheus metrics of the daemon at /metrics, without authentication. Keep it on 127.0.0.1 unless your monitoring server needs it.

Example

A server with rotated logs, pools in 10.210.0.0/16 and the bridge in 10.209.0.0/24, live-restore, a Docker Hub mirror and metrics on loopback:

daemon.json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2",
  "default-address-pools": [
    {
      "base": "10.210.0.0/16",
      "size": 24
    }
  ],
  "bip": "10.209.0.1/24",
  "registry-mirrors": [
    "https://mirror.gcr.io"
  ],
  "live-restore": true,
  "metrics-addr": "127.0.0.1:9323"
}

The commands that apply it

apply-commands.txt
[ ! -f /etc/docker/daemon.json ] || sudo cp -p /etc/docker/daemon.json /etc/docker/daemon.json.bak
sudo install -m 0644 -D daemon.json /etc/docker/daemon.json
sudo dockerd --validate --config-file /etc/docker/daemon.json
sudo systemctl restart docker
docker info --format '{{.LoggingDriver}} {{.Driver}} live-restore={{.LiveRestoreEnabled}}'
docker info --format '{{range .RegistryConfig.Mirrors}}{{println .}}{{end}}'
docker network create anaroq-pool-test
docker network inspect --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' anaroq-pool-test
docker network rm anaroq-pool-test
curl -s http://127.0.0.1:9323/metrics | head -n 5

Limits

  • Linux servers running Docker Engine. Docker Desktop and rootless Docker read their settings elsewhere and are not covered.
  • It writes a new file. Merge it by hand with keys you already have (insecure-registries, data-root, dns…), or they are lost.
  • Address pools apply to networks created after the restart: existing networks keep their ranges until you remove and recreate them.
  • IPv6 pools, TLS for the API socket and per-container log settings are not covered.

Not sure which ranges collide? Check your LAN and VPN against Docker's networks

Sources

  1. dockerd: daemon configuration file
  2. Docker Engine: configure logging drivers
  3. Docker Engine: live restore
  4. Docker Engine: storage drivers
  5. Docker Engine: collect metrics with Prometheus

Updated

Next step

Docker subnet conflict checker

A free public tool by ANAROQ, a company building compute infrastructure. What ANAROQ is building