更改docker 存储的路径
在如下版本及环境验证过:
[root@docker opt]# uname -a
Linux docker 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@docker opt]# rpm -qa|grep docker
docker-common-1.12.6-55.gitc4618fb.el7.centos.x86_64
docker-client-1.12.6-55.gitc4618fb.el7.centos.x86_64
docker-1.12.6-55.gitc4618fb.el7.centos.x86_64
创建软件来修改路径
rpm安装的docker的存储路径默认设置为:/var/lib/docker,可以使用docker info命令查看
[root@docker containers]# docker info|grep Root
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Docker Root Dir: /var/lib/docker
停止docker运行
[root@docker containers]# systemctl stop docker
将存储目录移动到指定路径(不移动原来的目录将创建一个全新的存储空间)
[root@docker containers]# cp /var/lib/docker /opt/ -rf
创建软链接
[root@docker ~]# cd /var/lib/
[root@docker lib]# pwd
/var/lib
[root@docker lib]# mv docker docker_bak
[root@docker lib]# ln -s /opt/docker docker
[root@docker lib]# ll docker
lrwxrwxrwx 1 root root 11 Oct 9 23:13 docker -> /opt/docker
启动docker并验证是否更改成功
[root@docker lib]# systemctl start docker
[root@docker lib]# docker info|grep Root
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Docker Root Dir: /opt/docker
修改docker 启动参数更改存储路径
rpm安装的docker的存储路径默认设置为:/var/lib/docker,可以使用docker info命令查看
[root@docker containers]# docker info|grep Root
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Docker Root Dir: /var/lib/docker
停止docker运行
[root@docker containers]# systemctl stop docker
将存储目录移动到指定路径(不移动原来的目录将创建一个全新的存储空间)
[root@docker containers]# cp /var/lib/docker /opt/ -rf
添加--graph启动参数指定存储路径
[root@docker opt]# cat /etc/sysconfig/docker|grep -v "^#"
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --graph=/opt/docker-1'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
也可以修改/usr/lib/systemd/system/docker.service 文件,但是要使用systemctl daemon-reload重载配置文件
启动docker并验证是否更改成功
[root@docker lib]# systemctl start docker
[root@docker lib]# docker info|grep Root
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Docker Root Dir: /opt/docker