一、停止 Docker 服务:
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop containerd
二、将 Docker 根目录移动到新的目录结构:
sudo mv /var/lib/docker /new_dir_structure
三、修改启动配置默认路径
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph=/new_dir_structure/docker
Docker Engine 17.05及以后版本
ExecStart=/usr/bin/dockerd --data-root=/new_dir_structure/docker
四、重启daemon
systemctl daemon-reload
五、重启docker
systemctl start docker
六、查看docker数据存储目录是否修改,并且查看之前的镜像是否存在
[root@ ~]#: docker info | grep "Docker Root Dir"
Docker Root Dir: /new_dir_structure/docker
docker images
七、如果之前的容器有挂载地址,那么需要变更挂载信息
1.查看原先的挂在信息
docker inspect 容器id
"Mounts": [
{
"Type": "bind",
"Source": "/usr/local/nginx/image",
"Destination": "/app/nginx/image",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/new_dir_structure/docker/volumes/hq_project_code/_data",
"Destination": "/app/app",
"Mode": "",
"RW": true,
"Propagation": "rslave"
}
],
2.修改挂载信息
/new_dir_structure/docker/containers/容器id 中的config.v2.json 和 hostconfig.json 文件。
找到里面挂载地址,修改为新的地址。 注意!!!! 一定要在docker服务关闭的时候修改,否则保存不上修改的内容,修改完后重启docker,然后 启动容器查看