Docker cheat sheet

Reference commands for Docker.
  1. Daemon
    1. Enable Docker to run at login
    2. Start or stop the daemon
  2. Login
  3. Config
    1. Enable large images
  4. Image management
  5. References

Daemon

Enable Docker to run at login

See post-install instructions for details.

sudo systemctl enable docker

Start or stop the daemon

sudo systemctl stop docker
sudo systemctl start docker
sudo systemctl restart docker

Login

docker login

Unencrypted password will save to ~/.docker/config.json by default on Linux. Refer to the docker-credential-pass guide for details on how to secure passwords.

For macOS, keychain integration is enabled when you install Docker.app.

Config

Inspect current config:

docker info

Important! Make sure “Docker Root Dir” is set outside of main partition for VMs with small local disks.

Enable large images

If you attempt to pull an image that is larger than 10 GB using the devicemapper storage driver, you may run into an error due to the current default configuration of the Docker daemon (dockerd) on Linux.

docker info &>2 > /dev/null | grep 'Base Device Size:'
docker info &>2 > /dev/null | grep 'Storage Driver:'

You can fix this by setting the default storage-opts for the Docker daemon. I recommend doing this with a JSON config file on Linux, which can be saved at /etc/docker/daemon.json.

Here’s a minimal configuration for the now deprecated devicemapper storage driver (still default on RHEL systems), increasing the default limit to 20 GB.

{
  "storage-driver": "devicemapper",
  "storage-opts": [
    "dm.basesize=20G"
  ]
}

Image management

Force remove an image:

docker image rm --force "<IMAGE ID>"

Delete all dangling data (recommended):

docker system prune

Remove all images, not just dangling ones:

docker system prune --all --force

References