简体   繁体   English

如何更改Docker映像存储的目录根目录

[英]How to change the dir root of docker image storage

I using docker to build some images. 我使用docker构建一些图像。 To space drive space I decide to change the default docker images and containers storage ('/var/lib/docker') to my additional drive ('/mnt') 为了空间空间,我决定将默认的docker映像和容器存储('/ var / lib / docker')更改为我的其他驱动器('/ mnt')

I change the '/lib/systemd/system/docker.service', and add 我更改了'/lib/systemd/system/docker.service',并添加了

'ExecStart=/usr/bin/dockerd -H fd:// -g /mnt/data'

The problem is when I indicate dir root like that it works like a charm, but if I want to go deeper, for example 问题是当我像这样指示dir root时,它像一个超级按钮一样工作,但是例如,如果我想更深入一点

'ExecStart=/usr/bin/dockerd -H fd:// -g /mnt/data/subFolder/AABB'

When I 'systemctl daemon-reload' and 'service docker restart' I got error: 当我'systemctl daemon-reload''service docker restart' ,出现错误:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Wed 2017-08-16 16:25:28 EDT; 46s ago
     Docs: https://docs.docker.com
  Process: 4543 ExecStart=/usr/bin/dockerd -H fd:// -g /mnt/data/subFolder/AABB (code=exited, status=1/FAILURE)
 Main PID: 4543 (code=exited, status=1/FAILURE)

Aug 16 16:25:28 myserver systemd[1]: Failed to start Docker Application Container Engine.
Aug 16 16:25:28 myserver systemd[1]: docker.service: Unit entered failed state.
Aug 16 16:25:28 myserver systemd[1]: docker.service: Failed with result 'exit-code'.
Aug 16 16:25:28 myserver systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Aug 16 16:25:28 myserver systemd[1]: Stopped Docker Application Container Engine.
Aug 16 16:25:28 myserver systemd[1]: docker.service: Start request repeated too quickly.
Aug 16 16:25:28 myserver systemd[1]: Failed to start Docker Application Container Engine.

I have check the ownership and right for them which are 我已经检查了所有权并适合他们

drwxr-xr-x 3 root root 4096 Aug 16 16:23 data
&
drwxrwxrwx 4 root  root 49 Aug  8 10:23 AABB

Does anyone have idea why that happens? 有谁知道为什么会这样? Any help appreciated! 任何帮助表示赞赏!

A bit update, I find after I change the root (eg"/mnt/data") the right of this folder is changed as well 进行了一些更新,我发现更改根目录(例如“ / mnt / data”)之后,该文件夹的右侧也被更改了

drwx--x--x 12 root root 4096 Aug 16 16:40 data

Although it is doable to change it back, It would be great if you can give me some clue 尽管可以将其改回,但如果您能给我一些提示,那将是很好的

Here is more update, the /subFolder/ seems to be NFS share folder, that might be the reason. 这是更多更新, /subFolder/似乎是NFS共享文件夹,这可能是原因。

So it there any way that I can use the folder as docker image and container storage? 因此,有什么方法可以将文件夹用作docker映像和容器存储?

images are sored in /var/lib/docker/overlay2 图像在/var/lib/docker/overlay2

you can move this folder and than create symlink to it new location 您可以移动此文件夹,然后创建符号链接到新位置

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

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

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