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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains how to modify Docker's default image and container storage location in CentOS. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "How to modify Docker's default image and container storage location in CentOS"!
How?
When trying to change Docker's default storage location, we must know something important.
Docker currently uses default storage locations
Storage drivers Docker currently uses
Mirrors and new storage space for containers
Docker default location is/var/lib/docker, where all current images and containers are stored. If you have any running containers, stop them and make sure no containers are running, then run the following command to determine which storage driver Docker is currently using. (You'll find out why in a later article)
# docker info
In the output message, look for the Storage Driver line and write it down. On my console it's devicemapper. The next step is to stop Docker services.
# sudo systemctl stop docker
Create a Drop-In file
The next step is to create a Drop-In file "docker.conf" in the directory/etc/systemd/system/docker.service.d, the default docker.service.d folder does not exist. So you have to create it first.
# sudo mkdir /etc/systemd/system/docker.service.d# sudo touch /etc/systemd/system/docker.service.d/docker.conf
The Drop-In file is created because we want Docker services to override the parameters used by default services in the/lib/systemd/system/docker.service file with specific parameters mentioned in the docker.conf file. If you want to learn more about Drop-In, read the system.unit documentation.
Define a new storage location
Now open docker.conf and add the following:
# sudo vi /etc/systemd/system/docker.service.d/docker.conf[Service]ExecStart= ExecStart=/usr/bin/dockerd --graph="/mnt/new_volume" --storage-driver=devicemapper
Save and exit the VI editor,/mnt/new_volume is the new storage location, and devicemapper is the storage drive used by the current docker. If your storage drive is different, enter the value you checked and noted in the first step. Docker official documentation provides more information about the various storage drives. Now you can reload the service daemon and start Docker service again. This will change the storage location of the new mirrors and containers.
# sudo systemctl daemon-reload# sudo systemctl start docker
To make sure everything is OK, run # docker info to check Docker's root directory. It will be changed to/mnt/new_volume
What if you already have existing containers and mirrors?
If you want to migrate existing containers and images to a new location, do not reload the daemon and start the docker service after modifying docker. conf. Move existing data in/var/lib/docker to a new location. Then create a symbolic link.
Note: I haven't tried the following, as I don't need to keep existing containers and mirrors, but these steps should work; if you encounter any problems and any alternatives please comment below. I will modify the post. Back up your data before you try anything adventurous.
# cp -rp /var/lib/docker /mnt/new_volume
Create a soft link (before creating a soft link, change the original/var/lib/docker directory to something else, such as/var/lib/docker-backup)
# mv /var/lib/docker /var/lib/docker-backup-2017-0510# ln -s /mnt/new_volume/docker /var/lib/docker
Then reload the daemon and start the docker service. There is no need to reload the daemon, just start the docker service.
# sudo systemctl daemon-reload # sudo systemctl start docker
The existing data should now be in the source directory of the soft chain, and the new containers and images will be stored in the new location,/mnt/new_volume/docker. Run # docker info to confirm.
(Note: If the steps are correct, the root directory should point to the soft link source directory/mnt/new_volume/docker, as follows: )
... omitted output
Name: dockerID: 5WBA:EF4D:WQ7P:DVRN:JCI4:LWDT:XSR2:G7RE:F5TI:PD3B:A57K:E4QADocker Root Dir: /mnt/new_volume/docker
omitted output
The author of this article is a writer of English. He is a writer of English.
At this point, I believe that everyone has a deeper understanding of "how to modify Docker's default image and container storage location in CentOS". Let's do it in practice! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to 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.
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.