A method, soft links

Docker default storage position is: / var / lib / docker

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

sudo docker info | grep "Docker Root Dir"

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 mirrored storage path modifications and container purposes.

This will be achieved by a method in flexible connection.

First we stopped Docker services:

systemctl restart docker或者service docker stop

And then move the entire / var / lib / docker directory path to the object:

mv /var/lib/docker /root/data/dockerln -s /root/data/docker /var/lib/docker

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.

 

Method two, and modify storage path mirroring 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.

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="/root/data/docker" --selinux-enabled -H fd://

If you add the following line Ubuntu (Ubuntu by default because not open selinux):

OPTIONS=--graph="/root/data/docker" -H fd://# 或者DOCKER_OPTS="-g /root/data/docker"

Finally restart, Docker on the path into / root / data / docker up.

centos7 down, you can

Modify docker.service file, use the -g parameter to specify the storage location

we /usr/lib/systemd/system/docker.service  

ExecStart=/usr/bin/dockerd --graph /new-path/docker 

 // reload the configuration file 

systemctl daemon-reload 

 // restart docker 

 

systemctl restart docker.service

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.

vim /etc/docker/daemon.json 

{"registry-mirrors": ["http://7e61f7f9.m.daocloud.io"],"graph": "/new-path/docker"}

 

Three methods to create a configuration file system

Creating a Drop-In File "docker.conf" In /etc/systemd/system/docker.service.d directory, the default docker.service.d folder does not exist. So you must first create it.

Drop-In reason for creating documents, is that we want Docker service, using specific parameters docker.conf mentioned in the document, the default parameters /lib/systemd/system/docker.service file located service uses covered. If you want to learn Drop-In, please read system.unit documents

New storage location defined now open docker.conf add the following:

# South you /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 a new storage location, and devicemapper is currently used for storage drive docker. If the value of your storage drive is different, the first step before you enter and view a note of. Docker official documentation provides more information about the various storage drives. Now, you can reload service daemon and start Docker served. This will change the position of the new image and storage container.

# sudo systemctl daemon-reload 

# sudo systemctl start docker

To make sure everything goes well, run # docker info command to check the Docker's root directory. It will be changed to / mnt / new_volume

 

Method IV, the use of docker-storage-set (docker1.12) command is executed

配置文件位置:/usr/lib/docker-storage-setup/docker-storage-setup或者/etc/sysconfig/docker-storage-setup、/etc/sysconfig/docker-storage

vim /etc/sysconfig/docker-storage

# This file may be automatically generated by an installation program.

# Please DO NOT edit this file directly. Instead edit

# /etc/sysconfig/docker-storage-setup and/or refer to

# "man docker-storage-setup".

# By default, Docker uses a loopback-mounted sparse file in

# /var/lib/docker.  The loopback makes it slower, and there are some

# restrictive defaults, such as 100GB max storage.

DOCKER_STORAGE_OPTIONS = - graph = "path to save."

or

DEVS=/dev/vdb

DATA_SIZE = 800GB (docker to change the default storage size)