简体   繁体   中英

how to change root dir of docker on ubuntu 18.04 LTS? (docker change location of volumes)

I installed ubuntu 18.04 LTS and checked a setting for docker (17.06.2-ce) to install at the same time.

I tested by starting the hello-world ( sudo docker run hello-world ) :

[...] Hello from Docker! This message shows that your installation appears to be working correctly. [...]

I mounted a software raid on the folder named /raid , and make a folder /docker-data in it.

I try to change the root dir of my docker to put it in /raid/docker-data/ by following the few tutorials on the network... in vain.

these solutions don't work either :

  • /etc/default/docker : I can't find this
  • As in the 2nd solution : docker can't find his folder.

Docker Root Dir: /var/snap/docker/common/var-lib-docker

Has anyone managed to do this feat in recent months?

(this is my 3rd installation of ubuntu and I just broke it...)


Apparently on Ubuntu 18.04 LTS, docker 17.06.2-it needs to work with snap, I'm going to dig this way. I will try to return answer later...

The common solution is to move the data and create a symlink:

systemctl stop docker
mv /var/lib/docker /raid/docker-data
ln -s /raid/docker-data /var/lib/docker
systemctl start docker

You can also tell docker about the new location with a setting in /etc/docker/daemon.json. If you don't have this file, you could create one with the contents:

{
  "data-root": "/raid/docker-data"
}

I would recommend the first solution since you will find many 3rd party tools expect docker to be located in /var/lib/docker.

Sorry for this late response.

to come to my problem, after having looked at it more closely:

I am on Ubuntu 18.04, I can add or remove the docker service only via snap install (or remove ) docker .

a docker party installs in /var/snap/

so I transpose your solution like this:

mv /var/snap/ /raid/snap
ln -s /raid/snap /var/snap

and finally I install docker via snap install docker

I have a test with sudo docker info , and I have this error message that appears :

cannot perform operation: mount --rbind /var/snap /tmp/snap.rootfs_RRAjdq//var/snap: Permission denied

( snap.rootfs_* because the end does not stop changing at each command launch)

and yet the installation went well some docker is apparently of course on /raid/snap .

I come back to you to give you the solution that allowed me to solve this problem.

cannot perform operation: mount --rbind /var/snap /tmp/snap.rootfs_RRAjdq//var/snap: Permission denied

I know why : https://bugs.launchpad.net/snapcraft/+bug/1620771 :

When /home is a symlink snaps don't work.

When /home is a real directory snaps work, see output below

In my case :

When /raid/snap is a symlink snaps don't work.

When /var/snap is a real directory snaps work.

I deleted docker. I had to reinstall snapcraf (snapd) because I was left on file modifications of it (wrong way)

from there, I stopped the snapd service:

sudo mv /var/snap/ /raid/snap
sudo mount --rbind /raid/snap /var/snap

I started the snapd service.

sudo snap install docker

sudo docker info <= to test

sudo docker run hello-world <= to test

I fixed my mount on fstab:

/raid/snap      /var/snap      none      bind

I restarted my OS : it worked, at least for my case. ( I checked all along this file consistency handling to see if the docker files was going well on the raid... )

Change Docker root storage (data path):

run this command to find docker data path:

$ sudo docker info | grep -i root

default path:

root@user-testing-HP-ProBook-4540s:/etc/docker# docker info | grep -i root
 Root Dir: /var/lib/docker/aufs
WARNING: No swap limit support
Docker Root Dir: /var/lib/docker

first, stop the docker:

sudo service docker stop

copy the corrent data path to new path:

sudo rsync -aqxP /var/lib/docker /data/docker-data/

add the following on (/etc/docker/daemon.json) file: (if the file is not there create the file with vim or your fav editor(sudo vim /etc/docker/deamon.json) )

{
  "data-root": "/data/docker-data/docker"
}

conform with cat command:

cat /etc/docker/deamon.json

output will be like this:

root@user-testing-HP-ProBook-4540s:/home/user/Downloads# cat /etc/docker/daemon.json 
{
  "data-root": "/data/docker-data/docker"
}

root@user-testing-HP-ProBook-4540s:/home/user/Downloads# 

start docker:

sudo service docker start

check the root (data path) path now:

$ sudo docker info | grep -i root

out put will be like this:

root@user-testing-HP-ProBook-4540s:/home/user/Downloads# sudo docker info | grep -i root
 

Root Dir: /data/docker-data/docker/aufs
WARNING: No swap limit support
Docker Root Dir: /data/docker-data/docker

root@user-testing-HP-ProBook-4540s:/home/user/Downloads# 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM