简体   繁体   English

如何在 ubuntu 18.04 LTS 上更改 docker 的根目录? (docker 更改卷的位置)

[英]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.我安装了 ubuntu 18.04 LTS 并检查了 docker (17.06.2-ce) 的设置以同时安装。

I tested by starting the hello-world ( sudo docker run hello-world ) :我通过启动 hello-world ( sudo docker run hello-world ) 进行了测试:

[...] Hello from Docker! [...] 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.我在名为/raid的文件夹上安装了一个软件raid,并在其中创建了一个文件夹/docker-data

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.我尝试按照网络上的几个教程更改我的 docker 的根目录以将其放在/raid/docker-data/ ……但徒劳无功。

these solutions don't work either : 这些解决方案也不起作用

  • /etc/default/docker : I can't find this /etc/default/docker :我找不到这个
  • As in the 2nd solution : docker can't find his folder.如第二个解决方案:docker 找不到他的文件夹。

Docker Root Dir: /var/snap/docker/common/var-lib-docker Docker 根目录:/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...) (这是我第三次安装 ubuntu,我刚刚把它弄坏了......)


Apparently on Ubuntu 18.04 LTS, docker 17.06.2-it needs to work with snap, I'm going to dig this way.显然在 Ubuntu 18.04 LTS 上,docker 17.06.2-它需要与 snap 配合使用,我打算以这种方式进行挖掘。 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.您还可以使用 /etc/docker/daemon.json 中的设置告诉 docker 新位置。 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.我会推荐第一个解决方案,因为您会发现许多 3rd 方工具都希望 docker 位于 /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 .我在 Ubuntu 18.04 上,我只能通过snap install (or remove ) docker添加或删除 docker 服务。

a docker party installs in /var/snap/一个 docker 聚会安装在/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最后我通过snap install docker

I have a test with sudo docker info , and I have this error message that appears :我对sudo docker info进行了测试,并且出现了以下错误消息:

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) snap.rootfs_*因为每次命令启动时结尾都不会停止更改)

and yet the installation went well some docker is apparently of course on /raid/snap .然而安装进行得很顺利,一些 docker 显然在/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 :我知道为什么: https : //bugs.launchpad.net/snapcraft/+bug/1620771

When /home is a symlink snaps don't work.当 /home 是符号链接时,快照不起作用。

When /home is a real directory snaps work, see output below当 /home 是一个真正的目录快照工作时,请参见下面的输出

In my case :就我而言:

When /raid/snap is a symlink snaps don't work.当 /raid/snap 是符号链接时,快照不起作用。

When /var/snap is a real directory snaps work.当 /var/snap 是一个真正的目录快照工作时。

I deleted docker.我删除了码头工人。 I had to reinstall snapcraf (snapd) because I was left on file modifications of it (wrong way)我不得不重新安装 snapcraf (snapd),因为我不得不修改它的文件(错误的方式)

from there, I stopped the snapd service:从那里,我停止了 snapd 服务:

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

I started the snapd service.我启动了 snapd 服务。

sudo snap install docker

sudo docker info <= to test sudo docker info <= 测试

sudo docker run hello-world <= to test sudo docker run hello-world <= 进行测试

I fixed my mount on fstab:我在 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... ) 我一直在检查这个文件一致性处理,看看 docker 文件在突袭中是否进展顺利......

Change Docker root storage (data path):更改 Docker 根存储(数据路径):

run this command to find docker data path:运行此命令以查找 docker 数据路径:

$ 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) )在 (/etc/docker/daemon.json) 文件中添加以下内容:(如果该文件不存在,请使用 vim 或您的收藏编辑器(sudo vim /etc/docker/deamon.json)创建文件)

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

conform with cat command:符合 cat 命令:

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# 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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