Docker – Random thoughts https://blog.adriel.co.nz Occasionally I think of things to write about. Sun, 28 Jan 2018 07:51:44 +0000 en-NZ hourly 1 https://wordpress.org/?v=6.0 Change Docker data directory on Debian https://blog.adriel.co.nz/2018/01/25/change-docker-data-directory-in-debian-jessie/ https://blog.adriel.co.nz/2018/01/25/change-docker-data-directory-in-debian-jessie/#comments Wed, 24 Jan 2018 22:16:17 +0000 https://adriel.co.nz/blog/?p=72 If you’ve installed Docker with the default settings on Debian, it will be storing Docker images, containers and volumes in /var/lib/docker, which will be an issue if you have /var on its own (usually small) partition.

After using Docker for a while you may start to run out of space on the /var partition, at which point you’ll need to either add more space to that partition or relocate it to somewhere with more space.

Here are the steps to change the directory even after you’ve created Docker containers etc.
Note, you don’t need to edit docker.service or init.d files, as it will read the change from the .json file mentioned below.

Steps

  1. Edit /etc/docker/daemon.json (if it doesn’t exist, create it)
  2. Add the following
    {
      "data-root": "/new/path/to/docker-data"
    }
  3. Stop docker
    sudo systemctl stop docker
  4. Check docker has been stopped
    ps aux | grep -i docker | grep -v grep
  5. Copy the files to the new location
    Optionally you could run this inside screen if you have a large amount of data or unreliable ssh connection.

    sudo rsync -axPS /var/lib/docker/ /new/path/to/docker-data

    Options explanation, check out the man page for more info

    -a, --archive             archive mode; equals -rlptgoD (no -H,-A,-X)
    -x, --one-file-system     don't cross filesystem boundaries
    -P                        show progress during transfer
    -S, --sparse              handle sparse files efficiently
  6. Start Docker back up
    sudo systemctl start docker
  7. Check Docker has started up using the new location
    docker info | grep 'Docker Root Dir'
  8. Check everything has started up that should be running
    docker ps

Leave both copies on the server for a few days to make sure no issues arise, then feel free to delete it.

sudo rm -r /var/lib/docker

Documentation / sources

Official docs https://docs.docker.com/engine/admin/systemd/

Docker GitHub issue item https://github.com/docker/docker/issues/3127

Blog post inspired by linuxconfig

Tested and working on Debian Stretch (9.3) with Docker Docker version 17.12.0-ce

]]>
https://blog.adriel.co.nz/2018/01/25/change-docker-data-directory-in-debian-jessie/feed/ 3