How to change Docker data directory

Changing the Docker Engine data directory moves the daemon's persistent state off the default system disk and onto a filesystem with more space or better performance. This is the usual fix when /var/lib/docker grows faster than the root volume can safely handle.

On current Linux hosts, the daemon reads its main storage path from /etc/docker/daemon.json and reports the active root through docker info. Upgraded hosts that still use classic storage drivers keep Docker data under /var/lib/docker, while fresh Docker Engine 29 installs that use the containerd image store keep image contents and container snapshots under /var/lib/containerd instead.

These steps assume a rootful Docker Engine installation managed by systemd. Stop the daemon before copying data, keep the original directories in place until the restart succeeds, and remember that rootless Docker uses different config and service paths.

Steps to change Docker data directory in Linux:

  1. Check the current Docker root directory so the existing path is confirmed before any change.
    $ docker info --format '{{.DockerRootDir}}'
    /var/lib/docker
  2. Check whether the daemon is using classic storage drivers or the containerd image store.
    $ docker info --format '{{json .DriverStatus}}'
    [["Backing Filesystem","extfs"],["Supports d_type","true"],["Using metacopy","false"],["Native Overlay Diff","true"],["userxattr","false"]]

    If the output looks like the example, the host is using classic storage drivers and changing data-root covers the whole Docker root. If the output is

    [["driver-type","io.containerd.snapshotter.v1"]]

    , image contents and container snapshots remain under /var/lib/containerd until containerd is moved separately.

  3. Create the new Docker data directory on the target filesystem.
    $ sudo mkdir -p /mnt/docker-data

    Replace /mnt/docker-data with the final mount point chosen for Docker storage. The destination should already exist on the disk or partition that will hold the data.

  4. Stop the Docker service before copying any data.
    $ sudo systemctl stop docker

    Stopping Docker stops running containers on the host and can interrupt workloads until the daemon starts again.

  5. Stop the containerd service only when the earlier DriverStatus check reported io.containerd.snapshotter.v1.
    $ sudo systemctl stop containerd

    Hosts that still use classic storage drivers can leave containerd alone because their Docker data remains under /var/lib/docker.

  6. Copy the current Docker root directory into the new location while preserving ownership and metadata.
    $ sudo cp -a /var/lib/docker/. /mnt/docker-data/

    Keep /var/lib/docker in place until the daemon starts cleanly from the new path and the expected images, containers, and volumes are visible after the restart.

  7. Create a separate containerd destination directory only when the earlier DriverStatus check reported io.containerd.snapshotter.v1.
    $ sudo mkdir -p /mnt/containerd-data
  8. Copy the current containerd root into the new location only when the earlier DriverStatus check reported io.containerd.snapshotter.v1.
    $ sudo cp -a /var/lib/containerd/. /mnt/containerd-data/

    Do not point containerd at the same directory used for Docker's data-root. The two daemons need separate storage roots.

  9. Edit /etc/docker/daemon.json and set the top-level data-root entry to the new Docker path.
    {
      "data-root": "/mnt/docker-data"
    }

    If /etc/docker/daemon.json already contains other keys, add or update only the data-root line inside the existing JSON object. If dockerd already gets --data-root from a systemd unit override, remove or update that override before restarting.

  10. Edit /etc/containerd/config.toml and set the root value only when the earlier DriverStatus check reported io.containerd.snapshotter.v1.
    version = 2
    root = "/mnt/containerd-data"

    This file is needed only for hosts using the containerd image store. Classic storage-driver hosts can skip this step.

  11. Start the containerd service only when the earlier DriverStatus check reported io.containerd.snapshotter.v1.
    $ sudo systemctl start containerd
  12. Start the Docker service with the new root directory in place.
    $ sudo systemctl start docker
  13. Verify that Docker now reports the new root directory.
    $ docker info --format '{{.DockerRootDir}}'
    /mnt/docker-data
  14. Confirm that the existing images or containers are still visible after the restart.
    $ docker image ls
    WARNING: This output is designed for human readability. For machine-readable output, please use --format.
    IMAGE         ID             DISK USAGE   CONTENT SIZE   EXTRA
    alpine:3.22   55ae5d250cae       13.5MB         4.23MB

    Remove or archive the old /var/lib/docker and /var/lib/containerd trees only after this check and the expected workload startup succeeds.