Recently I had an issue where I was using a mini computer to run some Docker services and I kept running out of space on the tiny 16GB hard drive. The hard drive for this machine was soldered on the motherboard so there was no possibility to add a larger drive. Considering Docker itself was using about 9GB of that space, the logical solution was to mount the data directory to another disk, which is this case was a low profile USB 3.1 thumb drive. The steps to complete this are quite simple and here they are:

  • First, you need to stop the Docker service:systemctl stop docker.service
  • Next, make a new directory somewhere within your mount point and copy the files:
    mkdir -p /path/to/new-docker
    rsync -aqxP /var/lib/docker/ /path/to/new-docker
  • Open /etc/docker/daemon.json and add the new data directory
  • Now the part noone tells you, make sure the external drive is mounted before the Docker service starts.
    • First, get the system mount unit
      systemctl list-units --type=mount
    • In my case, the USB was mounted to /media/jukebox/Samsung
    • Therefore, the mount unit is seen below is media-jukebox-Samsung.mount
    • Open docker service file and paste the mount unit at the end of the line beginning with After
      • Before: firewalld.service containerd.service
      • After edit: firewalld.service containerd.service media-jukebox-Samsung.mount
    • The service will now wait for that volume to be mounted before it starts.
  • Finally, Restart Docker
    systemctl start docker.service


How to move Dockers data directory

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *