In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to modify the default storage location of the image in Docker. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
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 reload configuration file $sudo systemctl daemon-reload # restart docker service $sudo systemctl start docker above is how to modify the default storage location of images in Docker. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.