Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to modify the default storage location of Docker images

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what are the ways to modify the default storage location of Docker images?", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the ways to modify the default storage location of Docker images?"

Due to the initial partition of the system, the corresponding / partition in the operating system will not be too large and will not be partitioned separately through the / var directory. If the Docker service is running above, after a long period of use, the already large partitions will become more and more inadequate. How to deal with this problem better?

1. Use soft links

We know that in the operating system, the Docker container is stored in the / var/lib/docker directory by default, and you can check the location with the following command.

# default location $sudo docker info | grep "Docker Root Dir"

The most direct and effective way to solve the problem of insufficient default storage capacity is to mount a new partition to this directory. However, under the condition that the original system space is unchanged, soft links are used to modify the storage path of the image and the container to achieve the same purpose.

# stop Docker service $systemctl restart docker # stop Docker service $service docker stop

Then move the entire / var/lib/docker directory to the destination path with less space. When you start Docker at this point, you find that the storage directory is still the / var/lib/docker directory, but it is actually stored on the data disk / data/docker.

# move the original content $mv / var/lib/docker / data/docker # to link $ln-sf / data/docker / var/lib/docker2. Specify container startup parameters

Specify the parameter of container startup-graph=/var/lib/docker in the configuration file to specify the image and container storage path. The configuration file of Docker can set most of the background process parameters, and the storage location is different in each operating system. The location in Ubuntu is the / etc/default/docker file and the location in CentOS is the / etc/sysconfig/docker file.

# CentOS6 # because Ubuntu enables the selinux mechanism OPTIONS=--graph= "/ data/docker" by default-- selinux-enabled-H fd:// # CentOS7 # modifies the docker.service file, and uses the-g parameter to specify the storage location $vi / usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd-- graph / new-path/docker# Ubuntu # because Ubuntu does not enable the selinux mechanism OPTIONS=--graph= "/ data/docker"-H fd:// by default

After rebooting, the path of Docker will be changed to / data/docker.

# restart the reload configuration file $sudo systemctl daemon-reload # restart the docker service $sudo systemctl restart docker.service

If the version of Docker is 1.12 or above, you can modify or create a new daemon.json file. The modification will take effect immediately, and there is no need to restart the Docker service.

# modify the configuration file $vim / etc/docker/daemon.json {"registry-mirrors": ["http://7e61f7f9.m.daocloud.io"]," graph ":" / new-path/docker "} 3. Create a configuration file under System

Create a Drop-In file docker.conf in the / etc/systemd/system/docker.service.d directory. The default docker.service.d folder does not exist and must be created first. The reason for creating the Drop-In file is that we want the Docker service to override the parameters in the / lib/systemd/system/docker.service file used by the default service with the specific parameters mentioned in the docker.conf file.

# define a new storage location $sudo vi / etc/systemd/system/docker.service.d/docker.conf [Service] ExecStart=/usr/bin/dockerd-- graph= "/ data/docker"-- storage-driver=devicemapper

Saving and exiting the vim editor / data/docker is the new storage location, and devicemapper is the storage driver currently used by Docker. If your storage driver is different, please enter the value you viewed and noted in the first step before. Now you can reload the service daemon and start the Docker service, which will change the storage location of the new images and containers. To make sure everything is going well, run the docker info command to check the root directory of Docker.

# restart the reload configuration file $sudo systemctl daemon-reload # restart the docker service $sudo systemctl start docker here, I believe you have a better understanding of "what is the way to modify the default storage location of Docker images", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report