修改docker默认存储目录
2023-09-24 本文已影响0人
Joening
安装启动docker
[root@localhost docker]# yum -y install docker-ce
Installed:
docker-ce.x86_64 3:24.0.6-1.el7
Dependency Installed:
docker-ce-rootless-extras.x86_64 0:24.0.6-1.el7
Complete!
[root@localhost docker]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
编写daemon.json配置文件在/etc/docker/目录中
[root@localhost docker]# tee /etc/docker/daemon.json <<-EOF
> {
> "data-root": "/www/docker"
> }
> EOF
{
"data-root": "/www/docker"
}
[root@localhost docker]#
[root@localhost docker]#
[root@localhost docker]#
[root@localhost docker]# cat /etc/docker/daemon.json
{
"data-root": "/www/docker"
}
启动docker服务
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker
检查配置是否生效
[root@localhost docker]# docker info |grep -y dir:
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Docker Root Dir: /www/docker
配置二
# 修改docker的根目录(默认根目录为:/var/lib/docker),根据需要来确定是否要修改
# 修改根目录,只是在启动命令后增加“--graph=/data/lib/docker”
$ vim /usr/lib/systemd/system/docker.service # 跳转到14行,修改如下
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/data/lib/docker