一、环境:
centos7.x系统,已经装好docker-ce服务包

二、查看当前docker的存储路径

[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 ~]$ docker info |grep Dir
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: 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默认的存储路径
  • 三、关闭docker服务
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 ~]$  systemctl stop docker            ## 关闭docker服务                            
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 ~]$ systemctl status docker		  ## 查看docker服务状态
  • 四、将原有数据迁移至新目录
[root@@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# mkdir /data/service/docker -p
[root@@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# mv /var/lib/docker/* /data/docker/
  • 五、修改docker.service配置文件,使用 --graph 参数指定存储位置
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /data/docker
  • 六、重新加载配置文件
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# systemctl daemon-reload
  • 七、启动docker服务
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# systemctl start docker
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# systemctl enable docker
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 local]# systemctl status docker
  • 八、查看修改是否成功
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 ~]# docker info | grep Dir
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: 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: /data/docker   #查看修改成功
[root@VM-13cb107e-b518-4d7b-a63f-3f0a5499ec76 ~]#
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐