Friday, April 8, 2022

[SOLVED] Move docker volume to different partition

Issue

I have a server where I run some containers with volumes. All my volumes are in /var/lib/docker/volumes/ because docker is managing it. I use docker-compose to start my containers.

Recently, I tried to stop one of my container but it was impossible :

$ docker-compose down
[17849] INTERNAL ERROR: cannot create temporary directory!

So, I checked how the data is mounted on the server :

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7,8G     0  7,8G   0% /dev
tmpfs           1,6G  1,9M  1,6G   1% /run
/dev/md3         20G   19G     0 100% /
tmpfs           7,9G     0  7,9G   0% /dev/shm
tmpfs           5,0M     0  5,0M   0% /run/lock
tmpfs           7,9G     0  7,9G   0% /sys/fs/cgroup
/dev/md2        487M  147M  311M  33% /boot
/dev/md4        1,8T  1,7G  1,7T   1% /home
tmpfs           1,6G     0  1,6G   0% /run/user/1000

As you can see, the / is only 20Go, so it is full and I can't stop my containers using docker-compose.

My questions are :

  • There is a simple solution to increase the available space in the /, using /dev/md4 ?

  • Or can I move volumes to another place without losing data ?


Solution

I landed here as I had the very same issue. Even though some sources suggest you could do it with a symbolic link this will cause all kinds of issues.

Depending on the OS and Docker version I had malformed images, weird errors or the docker-daemon refused to start.

Here is a solution, but it seems it varies a little from version to version. For me the solution was:

Open

/lib/systemd/system/docker.service

And change this line

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

to:

ExecStart=/usr/bin/dockerd -g /mnt/WHATEVERYOUR/PARTITIONIS/docker --containerd=/run/containerd/containerd.sock


Answered By - Qohelet
Answer Checked By - Timothy Miller (WPSolving Admin)