Due to the initial partitioning of the system, the corresponding / partition in the operating system will not be too large, and the /var directory will not be partitioned separately. If you run the Docker service on it, after a long period of use, the originally large partition will become increasingly insufficient. How to better deal with this problem? 1. Use soft linksWe know that in the operating system, by default, the storage location of the Docker container is under the /var/lib/docker directory. You can view the specific location through the following command. #Default storage 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, in the case that the original system space remains unchanged, the soft link method is adopted to modify the storage path of the image and container to achieve the same purpose. # Stop the Docker service $ systemctl restart docker # Stop the Docker service $ service docker stop Then move the entire /var/lib/docker directory to a destination path that does not take up too much space. When you start Docker at this time, you will 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 # Link $ ln -sf /data/docker /var/lib/docker 2. Specify container startup parametersIn the configuration file, specify the container startup parameter --graph=/var/lib/docker to specify the image and container storage path. Docker's configuration file can set most of the background process parameters, and its storage location is inconsistent in each operating system. The location in Ubuntu is /etc/default/docker file and the location in CentOS is /etc/sysconfig/docker file. # CentOS6 # Because Ubuntu enables the selinux mechanism by default OPTIONS=--graph="/data/docker" --selinux-enabled -H fd:// # CentOS7 # Modify the docker.service file and use 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 by default OPTIONS=--graph="/data/docker" -H fd:// After restarting, the Docker path is changed to /data/docker. # Reload the configuration file $ sudo systemctl daemon-reload # Restart the docker service $ sudo systemctl restart docker.service If the Docker version is 1.12 or above, you can modify or create a new daemon.json file. The modification will take effect immediately without restarting 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 SystemCreate a Drop-In file docker.conf in the /etc/systemd/system/docker.service.d directory. By default, the docker.service.d folder does not exist and must be created first. The reason for creating a Drop-In file is that we want the Docker service to use specific parameters mentioned in the docker.conf file, overwriting the parameters used by the default service in the /lib/systemd/system/docker.service 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 Save and exit 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, enter the value you checked and wrote down in the first step. You can now reload the service daemon and start the Docker service, which will change the location where the new images and containers are stored. To confirm that everything went well, run the docker info command to check the Docker root directory. # Reload the configuration file $ sudo systemctl daemon-reload # Restart the docker service $ sudo systemctl start docker This is the end of this article about how to modify the default storage location of Docker images. For more information about the default storage location of Docker images, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of flex and position compatibility mining notes
>>: Graphical explanation of the underlying principle of JavaScript scope chain
1. Docker Compose Overview Compose is a tool for ...
Relative Length Units em Description: Relative len...
This article example shares the specific code of ...
Using DOSBox, you can simulate DOS under Windows ...
The table caption can be placed above or below th...
MySQL allows you to create multiple indexes on th...
Normally, when you run a command in the terminal,...
Table of contents Preface Conversion relationship...
Table of contents 1. Data Manipulation Language (...
Table of contents 1. Introduction 2. Installation...
This article example shares the specific code of ...
You can have the best visual design skills in the...
The specific code for JavaScript to implement the...
need Configuring DingTalk alarms in Zabbix is s...
Preface: It’s the end of the year, isn’t it time ...