Mailing List Archive

Docker mounting strangeness.
Starting here in case it’s something specific to Gentoo since I can’t find anybody complaining about the behaviour elsewhere on the web.

I’m setting up an image to use Docker, which will be deployed on multiple machines. Since the containers will be large, I didn’t want them on the root partition.

Ok, easy enough, I just put it in fstab to mount a different partition on /var/lib/docker. Presto, now I don’t have to worry about a container using up all the OS’s disk space.

That’s where it gets weird.

Deploy the image, boot it up, everything is mounted correctly. But the first time (and ONLY the first time) I start Docker it somehow remounts the OS partition onto /var/lib/docker, and I end up with:

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 250G 0 disk
??sda1 8:1 0 123M 0 part /boot/efi
??sda2 8:2 0 3.8G 0 part
??sda3 8:3 0 14.2G 0 part /var/lib/docker
? /
??sda4 8:4 0 19.2G 0 part /var/opt
??sda5 8:5 0 9.5G 0 part
??sda6 8:6 0 203.1G 0 part /var/lib/docker

It puts all of Docker’s files on the OS partition at that point. (?.?)7

But if I turn Docker off, unmount everything from /var/lib/docker, and then remount just sda6 to /var/lib/docker, then when I restart Docker it puts everything on sda6 for me like I wanted, and continues to do so on reboots and Docker restarts after that…

Everything I find on the web is about how mounting stuff on /var/lib/docker *inside* a container will cause all kinds of problems… But that’s not what I’m doing… If it mangled the mounts every time, I could understand that too. But this seems strange. Is there some magic button I’m supposed to push to tell it not to mess with its data dir?

Running OpenRC by the way, if that makes a difference.

LMP
Re: Docker mounting strangeness. [ In reply to ]
On 01/12/2022 21:48, Laurence Perkins wrote:
> I’m setting up an image to use Docker, which will be deployed on
> multiple machines.  Since the containers will be large, I didn’t want
> them on the root partition.
>
> Ok, easy enough, I just put it in fstab to mount a different partition
> on /var/lib/docker.  Presto, now I don’t have to worry about a container
> using up all the OS’s disk space.

I don't know what's wrong in your case, but in order to have docker
store its files elsewhere, I created this file:

/etc/docker/daemon.json

with this in it:

{
"data-root": "/mnt/Data/cache/docker"
}

I stopped the docker daemon and did:

mkdir /mnt/Data/cache/
mv /var/lib/docker /mnt/Data/cache/

as root. Then started the docker daemon again and it worked.

/etc/docker/daemon.json is useful for other settings as well, like
enabling BuildKit by default without having to specify it on the command
line every time. I use:

{
"data-root": "/mnt/Data/cache/docker",
"features": { "buildkit": true }
}