转载请注明转载自:忆雨林枫

CENTOS 7.5 修改docker的overlay的默认路径

CENTOS 7.5 修改docker的overlay的默认路径

由于是使用默认安装的docker,没有修改它的存储路径,导致现在docker的overlay占满了根目录,所以不得不修改存储所在的目录。

找到docker的服务配置文件docker.service
对于CentOS7.5是在 /usr/lib/systemd/system/docker.service
如果不知道,可以find找出来。

编辑docker.service

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
–add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
–default-runtime=docker-runc \
–exec-opt native.cgroupdriver=systemd \
–userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
–init-path=/usr/libexec/docker/docker-init-current \
–seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES

添加一行 –graph=/opt/data/docker #这是docker存储的新位置,也是我想要存放的位置

对比前后

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
–add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
–default-runtime=docker-runc \
–exec-opt native.cgroupdriver=systemd \
–userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
–init-path=/usr/libexec/docker/docker-init-current \
–seccomp-profile=/etc/docker/seccomp.json \
–graph=/opt/data/docker \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES

重启docker
systemctl daemon-reload
systemctl restart docker
查看当前docker的信息
docker info
可以看到
Docker Root Dir: /opt/data/docker
说明已经修改成功了