Centos7 modify Docker default storage location

I. Introduction

After Centos7 installs docker, the default image and container storage path is /var/lib/docker, you can use the command docker info to view.

However, this path uses the storage of the system disk by default. If the data disk is mounted, you need to modify the default storage path of docker to the mount directory of the data disk, and you need to modify the relevant configuration of docker.

2. Steps

Change setting

Add --graph /data/docker after the ExecStart field in the docker.service file, where /data/docker is the storage directory you need to modify

mkdir -p /data/docker
vim /usr/lib/systemd/system/docker.service

will

ExecStart=/usr/bin/dockerd -H fd://--containerd=/run/containerd/containerd.sock

change into:

ExecStart=/usr/bin/dockerd --graph /data/docker -H fd://--containerd=/run/containerd/containerd.sock

Restart service

systemctl daemon-reload
systemctl restart docker

When you execute docker info again, you can see that the directory has been modified:

# docker info|grep 'Docker Root Dir'
 Docker Root Dir:/data/docker

Three, test

Download a redis image

docker pull redis

View sha256

# docker inspect -f {{".Id"}} redissha256:c33c9b2541a8fea04fe621e1e9d4e5973d9062f2a4eaac7a8d8b82c23c1b0aa8

View storage directory

# ls -l /data/docker/image/overlay2/imagedb/content/sha256/
Total amount 8-rw-------1 root root 664812 3117:25 c33c9b2541a8fea04fe621e1e9d4e5973d9062f2a4eaac7a8d8b82c23c1b0aa8

Reference link for this article:

https://blog.csdn.net/bacteriumX/article/details/88417098

https://www.jianshu.com/p/8cd83436373b

Recommended Posts

Centos7 modify Docker default storage location
CentOS 7 install Docker
CentOS7 install Docker
Docker installation (CentOS7 installation)
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
Modify CentOS hostname
CentOS 6 install Docker
Centos8 install Docker
Modify the default encoding of mysql5.6 under CentOS7
Install Docker on Centos7
CentOS 7 install Docker service
CentOS 8.0 installs docker error
CentOS 8-dnf install docker
install Docker on centos6.5
Docker CentOS installation method
CentOS 7 install Docker CE
Centos7 docker installation details
Build docker environment under Centos6.5
Install docker transfer on Centos7
Install docker on Centos system
Centos system modify time zone
CentOS environment installation of Docker
Docker EE installation on centos7