Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 980
Manu Avatar asked Jan 01 '23 19:01

Manu


2 Answers

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.

like image 150
BMitch Avatar answered Jan 04 '23 08:01

BMitch


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.

like image 22
Manu Avatar answered Jan 04 '23 08:01

Manu