一、安装路径查看
[root@node05002 ~]# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 1.13.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: 8891bca22c049cd2dcf13ba2438c0bac8d7f3343 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
WARNING: You're not using the default seccomp profile
Profile: /etc/docker/seccomp.json
selinux
Kernel Version: 3.10.0-862.11.6.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 8
Total Memory: 15.67 GiB
Name: node05002
ID: I5OZ:BZKS:UBQK:N7FD:ESWL:XNCH:HIFF:QSTD:TRKS:PRTC:CH2U:QXUM
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Registries: docker.io (secure)
找到Docker Root Dir: /var/lib/docker
二、目录迁移
在开始迁移之前,首先复制原 Docker 安装(存储)目录到新的路径下:
cp -a /var/lib/docker /opt/store/software/
然后备份原目录数据:
mv -u /var/lib/docker/ /var/lib/docker.bak
三、操作方法
3.1 方法一:软连接
[root@node05002 software]# ln -fs /opt/store/software/docker/ /var/lib/docker
[root@node05002 software]# service docker restart
Redirecting to /bin/systemctl restart docker.service
3.2 方法二:直接修改 Docker配置文件
Docker 版本 < v17.05.0
因为 dockerd 运行 Docker 服务的时候可以通过参数 graph
指定镜像和容器存放路径,比如: –graph=/var/lib/docker
,我们只需要修改配置文件指定启动参数即可。
Docker 的配置文件可以设置大部分的后台进程参数,在各个操作系统中的存放位置不一致,在 Ubuntu 中的位置是: /etc/default/docker
,在 CentOS 中的位置是: /etc/sysconfig/docker
。
如果是 CentOS 则添加下面这行:
OPTIONS=--graph="/opt/store/software/docker" --selinux-enabled -H fd://
如果是 Ubuntu 则添加下面这行(因为 Ubuntu 默认没开启 selinux):
OPTIONS=--graph="/opt/store/software/docker" -H fd://
或者
DOCKER_OPTS="-g /opt/store/software/docker"
Docker 版本 >= v17.05.0
因为 Docker 官方在这个发行版本就 deprecated 了 graph
这个 feature,所以如果你机器上安装的 Docker 版本 >= v17.05.0,则无法通过在 /etc/default/docker
配置文件中指定 graph
参数来修改 Docker 的默认安装(存储)目录了,具体参见官网文档:Docker Docs。
好在天无绝人之路,新版本的 Docker 还有其他方式可以达到我们修改安装(存储)目录的目的:通过修改(新建) /etc/docker/daemon.json
,指定 data-root
参数的值。
按如下操作:
vim /etc/docker/daemon.json
加入
{
"data-root": "/opt/store/software/docker",
"storage-driver": "overlay2" # 这个是 Docker 是默认设置,这里也可以不用加
}
重启 Docker & 清理原安装(存储)目录
最后,重启 Docker 服务: