Docker修改默认数据存放位置

方法一

# 查看Docker目前存储位置
[root@docker ~]# docker info | grep -i dir
 Docker Root Dir: /var/lib/docker
 
# 关闭Docker
[root@docker ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket

# 迁移原有数据
[root@docker ~]# mkdir /data/docker
[root@docker ~]# mv /var/lib/docker/* /data/docker/

# 修改docker的systemctl管理文件,使用--graph指定存储位置
[root@docker ~]# cat /usr/lib/systemd/system/docker.service
............................
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /data/docker
............................
[root@docker ~]# systemctl daemon-reload 
[root@docker ~]# systemctl start docker
[root@docker ~]# docker info | grep -i dir
 Docker Root Dir: /data/docker

方法二

# 查看Docker目前存储位置
[root@docker ~]# docker info | grep -i dir
 Docker Root Dir: /var/lib/docker
 
# 关闭Docker
[root@docker ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket

# 迁移原有数据
[root@docker ~]# mkdir /data/docker
[root@docker ~]# mv /var/lib/docker/* /data/docker/

# 修改配置文件,graph指定docker默认数据存放位置
[root@docker ~]# cat /etc/docker/daemon.json 
{
	"graph": "/data/docker"
}

# 启动docker
[root@docker ~]# systemctl start docker
[root@docker ~]# docker info | grep -i dir
 Docker Root Dir: /data/docker
Logo

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

更多推荐