Docker] how to modify the default image storage location of Docker

How big rivers and lakes, there are a lot of pit ......
server I use, the system root directory only 20G, Docker default image file is installed in / var / lib in / docker directory, so I did not install too many mirrors before encountered a situation that is too big docker service read and write operations on the disk, but also soft connection, causing the server's disk is unavailable, of course, the test environment using a virtual server. So in this situation we need to adjust.

Server environment: centos7, docker1.12.6

 

Scenario 1: Use a soft link mode (not recommended, you can look at)
the default storage location Docker case is: / var / lib / docker

You can use the following command to view the specific location:

sudo docker info | grep "Docker RootDir "
to solve this problem, the most direct way is to mount the partition to this directory, but my data disk there are other things, it is certainly hard to manage, so the use of storage containers and modify the mirror way path to achieve the purpose.

This will be achieved by a method in flexible connection.

 

1. First stopped Docker services:

systemctl restart docker

or

service docker stop
data file to be 2. Before backup

-zcC the tar / var / lib / docker> / mnt / var_lib_docker-Backup - $ (DATE +% S) .tar.gz
3. Then the whole migration / var / lib / docker directory path to the object:

mv / var / lib / Docker / the Data / Tools / Docker
4. build symlink soft links (not their own Google)

-s LN / Data / Tools / Docke / var / lib / Docker
5. The type of acknowledgment folder type symlink

-al LS / var / lib / Docker
6. At this time found that start Docker storage directory is still / var / lib / docker, but the fact is, you can see the changes stored in the data disk capacity on the data plate.

sudo systemctl start docker
Scheme 2: Modify the default image storage path and the container
 

Parameters specified storage path and image containers are --graph = / var / lib / docker, we only need to modify the configuration file to specify parameters to start. There is just hung on the disk 300g / data directory, a new file path / data / tools / docker in this directory

1.Docker configuration file can be set most parameters of the background process, inconsistencies in the storage position of each operating system, location in Ubuntu is: / etc / default / docker, CentOS position is: / etc / sysconfig / docker.

If CentOS6 then add the following line:

OPTIONS = - graph = "/ data / tools / docker" - selinux-enabled -H fd: //
If you add the following line Ubuntu (Ubuntu by default because not open selinux):

OPTIONS=--graph="/data/tools/docker" -H fd://#
或者

DOCKER_OPTS = "- g / data / tools / docker"
last restart, Docker on the path into / data / tools / docker up.

If CentOS7 is used as follows:

Docker.service modify files using --graph parameter specifies the storage location

sudo vim /usr/lib/systemd/system/docker.service 
text: ExecStart = / usr / bin / dockerd following add the following:

--graph /data/tools/docker
 

2. Modify the completion reload the configuration file

systemctl-daemon reload sudo
3. Restart docker Service

systemctl the restart docker.service the sudo
4. modify the default storage path task has been completed, look under a "non-root added docker omitted the sudo user group (c)"

NOTE: If docker is 1.12 or later, you can modify daemon.json file (or new). After the changes will take effect immediately, without restarting docker service.

sudo vim /etc/docker/daemon.json
modified as follows:

{
"Registry-Mirrors": [ "HTTP: //***.***.com"],
"Graph": "/ Data / Tools / Docker"
}
 5. The hope you can successfully complete the operation, there is a problem as far as possible Tell me what network or multiple document right, there is a surprise!

*****************************2019.04.26**************************'

17 and the latest version is used instead of `graph` a` data-root`, modify here please confirm your docker good version, the latest of the latest requirements and rules

vim /etc/docker/daemon.json

{
"data-root":"/home/qadev/.dockerlib",
"registry-mirrors":["https://je5rsr46.mirror.aliyuncs.com"]
}

---------------------
Disclaimer: This article is CSDN blogger "jwensh 'original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/u013948858/article/details/78424115

Guess you like

Origin www.cnblogs.com/yangww/p/11334895.html