如何更改docker镜像安装目录? [英] How to change the docker image installation directory?
问题描述
据我所知,docker 镜像在被拉取时会安装到 /var/lib/docker
.有没有办法更改此位置,例如更改为 /mnt
之类的已安装卷?
From what I can tell, docker images are installed to /var/lib/docker
as they are pulled. Is there a way to change this location, such as to a mounted volume like /mnt
?
推荐答案
使用最新版本的 Docker,您可以在 中将
(根据 https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file).data-root
参数的值设置为您的自定义路径/etc/docker/daemon.json
With recent versions of Docker, you would set the value of the data-root
parameter to your custom path, in /etc/docker/daemon.json
(according to https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file).
对于旧版本,您可以在启动 Docker 守护程序时使用 -g
选项更改 Docker 的存储基础目录(容器和图像所在的位置).(检查docker --help
).您可以在 Docker 启动时自动应用此设置,方法是将其添加到 /etc/default/docker
With older versions, you can change Docker's storage base directory (where container and images go) using the -g
option when starting the Docker daemon. (check docker --help
).
You can have this setting applied automatically when Docker starts by adding it to /etc/default/docker
这篇关于如何更改docker镜像安装目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!