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
If your DOCTYPE is as follows: Copy code The code ...
Preface When developing WeChat applets, you often...
This rookie encountered such a problem when he ju...
EXPLAIN shows how MySQL uses indexes to process s...
Global Object All modules can be called global: r...
Table of contents Written in front 1. Ngixn image...
1. Problem Description For security reasons, the ...
Table of contents Scenario Effect Code Summarize ...
Table of contents Preface Detect Zookeeper servic...
Do you know what fonts are used in the logo desig...
1. MySQL download address; http://ftp.ntu.edu.tw/...
Table of contents Declare fonts with font-face co...
Table of contents 1. Basic Introduction to JavaSc...
Table of contents What is insert buffer? What are...
Table of contents A pitfall about fileReader File...