Home  >  Article  >  Operation and Maintenance  >  How to change the docker storage directory

How to change the docker storage directory

王林
王林forward
2020-12-23 09:51:114372browse

How to change the docker storage directory

Background of the article:

In the development environment, because the docker test server runs too many containers and images, the disk space is often filled up. So now I decided to change the docker storage directory to the new mount point.

(Learning video sharing: Programming video)

1. Check Docker disk usage

docker system df

2. Clean the disk

docke system prune

Delete useless data volumes of closed containers and network untagged images -a parameter Useless images will also be deleted (use with caution)

3. Stop the Docker service

systemctl stop docker

4 , Migrate data directory

rsync -avz /var/lib/docker /data/docker/lib/

/var/lib/docker: docker default data directory/var/lib/docker: target directory, you need to create it before execution

5. Configure mapper File

Modify according to the installation configuration file of the docker service

vi /usr/lib/systemd/system/dokcer.service

Add attributes in ExectStart=xxx

ExectStart=xxx --graph /data/docker/lib/docker

Re-update the docker service

systemctl disable docker
systemctl enable docker
systemctl daemon-reload
systemctl start docker

6 . Check

docker info

and you will see the following information indicating success.

Docker Root Dir: /data/docker/lib/docker

Execute docker images and you will see that all previous images have been synchronized.

Related recommendations: docker tutorial

The above is the detailed content of How to change the docker storage directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete