Centos7 Docker modify the default storage location

I. Introduction

After installation Centos7 docker, and a container for storing default image path / var / lib / Docker , can use the command docker info view.

However, this route is used by default disk storage system, if the mounted disk data, the need to modify the default storage path docker to mount the disk directory data, the need to modify the configuration of the docker.

Second, step

Change setting

Will be --graph /data/dockeradded to the docker.servicefile ExecStartbehind the field where /data/dockeryou need to modify the storage directory

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

 

Then perform docker infowhen to see the catalog has been modified:

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

 

Third, the test

Download a redis image

docker pull redis

 

View sha256

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

 

View storage directory

# ls -l /data/docker/image/overlay2/imagedb/content/sha256/
总用量 8
-rw------- 1 root root 6648 12月 31 17:25 c33c9b2541a8fea04fe621e1e9d4e5973d9062f2a4eaac7a8d8b82c23c1b0aa8

 

 

This article reference links:

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

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

Guess you like

Origin www.cnblogs.com/xiao987334176/p/12125643.html