HON’s Wiki # Docker

Home / Containers

Contents

Setup (Debian)

Main config: /etc/docker/daemon.json

  1. Install: Install Docker Engine on Debian (Docker Documentation).
  2. (Optional) Setup swap limit:
    • If docker info contains WARNING: No swap limit support, it’s not working properly and should maybe be fixed.
    • Enabling/fixing it incurs a small performance degredation and is optional but recommended.
    • In /etc/default/grub, add cgroup_enable=memory swapaccount=1 to GRUB_CMDLINE_LINUX.
    • Run update-grub and reboot the system.
  3. Enable experimental features:
    1. In the config, set "experimental": true.
  4. (Recommended) Setup IPv6 firewall and NAT:
    • (Info) By default, Docker does not enable IPv6 for containers and does not add any IP(6)Tables rules for the NAT or filter tables, which you need to take into consideration if you plan to use IPv6 (with or without automatic IPTables rules). See the miscellaneous not below on IPv6 support for more info about its brokenness and the implications of that. Docker does however recently support handling IPv6 subnets similar to IPv4, meaning using NAT masquerading and appropriate firewalling. It doesn’t work properly for internal networks, though, as it breaks IPv6 ND. The following steps describe how to set that up, as it is the only working solution IMO. MACVLANs with external routers will not be NAT-ed.
    • Open the main config.
    • Set "ipv6": true to enable IPv6 support at all.
    • Set "fixed-cidr-v6": "fd8c:0c98:8726:3a42::/64" (example) to some random (ULA) (if using NAT masq.) or routable (GUA or ULA) (if not using NAT masq.) /64 prefix, to be used by the default bridge.
    • Set "ip6tables": true to enable automatic filter and NAT rules through IP6Tables (required for both security and NAT).
  5. (Recommended) Change the cgroup manager to systemd:
    • In the main config, set "exec-opts": ["native.cgroupdriver=systemd"].
    • It defaults to Docker’s own cgroup manager/driver called cgroupfs.
    • systemd (as the init system for most modern Linux systems) also functions as a cgroup manager, and using multiple cgroup managers may cause the system to become unstable under resource pressure.
    • If the system already has existing containers, they should be completely recreated after changing the cgroup manager.
  6. (Optional) Change the storage driver:
    • By default it uses the overlay2 driver, which is recommended for most setups. (aufs was the default before that.)
    • The only other alternatives worth consideration are btrfs and zfs, if the system is configured for those file systems.
  7. (Recommended) Change IPv4 network pool:
    • (Note) For local networks (not Swarm overlays), it defaults to pool 172.17.0.0/12 with /16 allocations, resulting in a maximum of 2^(16-12)=16 allocations. No IPv6 pool is allocated by default.
    • In the main config, set "default-address-pools": [{"base": "10.194.0.0/16", "size": 24}, {"base": "fd34:93c7:6fa8::/48", "size": 64}] (example).
    • Note: Address pools are currently broken for IPv6, see moby/moby#41438.
  8. (Recommended) Change default DNS servers for containers:
    • In the main config, set "dns": ["1.1.1.1", "2606:4700:4700::1111"] (example using Cloudflare) (3 servers max).
    • It defaults to 8.8.8.8 and 8.8.4.4 (Google).
  9. (Optional) Change the logging options (JSON file driver):
    • It defaults to the JSON file driver with a single file of unlimited size.
    • Configured globally in the main config.
    • Set the driver: "log-driver": "json-file" (default json-file)
    • Set non-blocking logging to avoid logging back-pressure from the logging driver, see the log options below. This might cause messages to be dropped if the logging buffer overflows.
    • Set log options in "log-opts": {}:
      • Set non-blocking logging: "mode": "non-blocking"
      • Set logging buffer size: "max-buffer-size": "5m"
      • Set the max number of files (for log rotation): "max-file": "5" (default 5)
      • Set the max file size: "max-size": "10m" (default 20m)
      • Set the compression for rotated files (for json-file): "compress": "true" (default true)
  10. (Recommended) Disable the userland proxy:
    • It’s no longer recommended to keep this enabled, future Docker versions will brobably disable it by default.
    • Disabling it may break your published IPv6 ports, so you may want to test that. As of late 2023, only IPv6 localhost port forwarding seems to be affected, any “real” address seems to work as intended.
    • In the main config, set "userland-proxy": false.
  11. (Optional) Change the container network MTU:
    • Path MTU discovery seems to be broken in Docker networks, causing connection problems when the upstream network is using an MTU lower than 1500.
    • In the main config, set "mtu": 1280 (for the minimum for IPv6) or similar.
  12. (Optional) Enable Prometheus metrics endpoint:
    • This only exports internal Docker metrics, not anything about the containers (use cAdvisor for that).
    • In the main config, set "metrics-addr": "[::]:9323".
  13. (Optional) Allow non-root users to use Docker:
    • This is not recommended on servers as it effectively grants them root access without sudo.
    • Add them to the docker group.

Full main config example: daemon.js

Docker Compose

  1. Install Docker: See above.
  2. Install: Docker Documentation: Install Docker Compose.
  3. Install command completion: Docker Documentation: Command-line completion.

NVIDIA Container Toolkit

The toolkit is used for running CUDA applications within containers.

  1. Add the repo: See the installation guide.
  2. Install: apt install nvidia-container-toolkit (not nvidia-docker2)
  3. Fix an ldconfig bug (Debian 11): In /etc/nvidia-container-runtime/config.toml, under the nvidia-container-cli section, set ldconfig = "/sbin/ldconfig" (remove the @ prefix).
  4. Test: docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

Usage

Networking

Best Practices

Miscellanea

IPv6 Support

Other Problems

Troubleshooting

Fix Docker Compose No-Exec Tmp-Dir

Docker Compose will fail to work if /tmp is mounted with noexec.

  1. Move /usr/local/bin/docker-compose to /usr/local/bin/docker-compose-normal.
  2. Create /usr/local/bin/docker-compose with the contents below and make it executable.
  3. Create the new TMPDIR dir.

New docker-compose:

#!/bin/bash
# Some dir without noexec
export TMPDIR=/var/lib/docker-compose-tmp
/usr/local/bin/docker-compose-normal "$@"

Useful Software


hon.one | HON95/wiki | Edit page