Moving docker root folder to a new drive / partiti

2020-07-18 07:08发布

问题:

I am trying to move the "/var/lib/docker" folder from one disk to another since that is taking up too much space. I keep running into some errors relating to permissions!

According to these questions:

  • How do I move a docker container's image to a persistent disk?
  • How to run docker LXC containers on another partition?

My disk is mounted on "/data" and I copied the "/var/lib/docker" folder to "/data/docker"

This is what I tried:

  • Tried out the -g flag from DOCKER_OPTS with "/data/docker"
  • Tried creating a symbolic link from the new disk drive
  • I tried doing a bind mount from /data/docker

However in all the cases, I get an error when I try to launch services inside my container about missing permissions to write to "/dev/null" (as user root).

I simply did a copy of the folder to the new disk. This copied all the permissions as well (This is an ext4 system with same filesystem level permissions as the original disk on which docker exists now).

Specs:

  • The fileystem I am using is aufs.
  • Docker version is 0.7.6
  • Ubuntu 12.04

How do I move the data properly? Do I need a upgrade first?

回答1:

I just did the following and it seems to work well:

as root:

service docker stop
mv /var/lib/docker /data/
# reboot and get root
service docker stop
rm -rf /var/lib/docker && ln -s /data/docker /var/lib/
service docker start


回答2:

To add custom startup options to docker in Debian / Ubuntu (such as using a different data directory):

Edit /lib/systemd/system/docker.service:

[Service]
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/docker -d $DOCKER_OPTS -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity

In /etc/default/docker set :

DOCKER_OPTS="-g /srv/docker"


In more recent Docker versions on Ubuntu you need to edit /etc/default/daemon.json:

{
    "data-root": "/new/location"
}


标签: docker lxc