Modify the storage location of the Docker image

The first way:
Docker's image and some data are in the /var/lib/docker directory, which occupies the Linux system partition, which is the following /dev/vda1. When there are multiple images, /dev The space of /vda1 may be insufficient, we can mount the docker data to the data disk, for example: /dev/vdb directory.
[root@10-10-63-106 docker]# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 20G 3.8G 16G 20% /
devtmpfs devtmpfs 916M 0 916M 0% /dev
tmpfs tmpfs 921M 0 921M 0% /dev/shm
tmpfs tmpfs 921M 43M 878M 5% /run
tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb xfs 100G 11G 90G 11% /data
         The main steps are as follows:
(1) First, backup the fstab file
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
(2) Stop docker, and use rsync to synchronize /var/lib/docker to the new location.
        If rsync is not installed, use yum -y intall rsync to install it, stop docker, service docker stop, and create a file to be mounted in the data partition directory, mkdir /data/docker Use the rsync tool to synchronize, rsync -aXS /var/lib/docker/. /data/docker/, this may take a long time, depending on the size of /var/lib/docker,
(3) Modify fstab
and add the following line to fstab in the file, and mount the new location to the /var/lib/docker
/data/docker /var/lib/docker none bind 0 0
file as follows:
[ root@10-10-63-106 docker]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jul 31 07:50:13 2014
#
# Accessible filesystems, by reference, are maintained under '/ dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/vda1 / xfs errors=remount-ro 0 1
/swapfile none swap defaults 0 0
/dev/vdb /data xfs defaults,noatime 0 0
/data/docker /var/lib/docker none bind 0 0
(4) re Mount
mount -a
(5) Use the following command to check
   df /var/lib/docker/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vdb 104806400 47204 104759196 1% /var/lib/docker
(6) Enter Container to view our space
bash-4.1# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
rootfs rootfs 9.8G 1.4G 7.9G 15% /
tmpfs tmpfs 921M 0 921M 0% /dev
shm          tmpfs     64M     0   64M   0% /dev/shm
/dev/vdb       xfs    100G  2.1G   98G   3% /etc/resolv.conf
/dev/vdb       xfs    100G  2.1G   98G   3% /etc/hostname
/dev/vdb       xfs    100G  2.1G   98G   3% /etc/hosts
tmpfs        tmpfs    921M     0  921M   0% /run/secrets
tmpfs        tmpfs    921M     0  921M   0% /proc/kcore
没有更改/var/lib/docker路径之前的情况:
bash-4.1# df -lhT
Filesystem    Type    Size  Used Avail Use% Mounted on
rootfs      rootfs    9.8G  1.4G  7.9G  15% /
tmpfs        tmpfs    921M     0  921M   0% /dev
shm          tmpfs     64M     0   64M   0% /dev/shm
/dev/vda1      xfs     20G   13G  6.9G  66% /etc/resolv.conf
/dev/vda1      xfs     20G   13G  6.9G  66% /etc/hostname
/dev/vda1      xfs     20G   13G  6.9G  66% /etc/hosts
tmpfs        tmpfs    921M     0  921M   0% /run/secrets
tmpfs        tmpfs    921M     0  921M   0% /proc/kcore
宿主机中的分区大小信息:
[root@10-10-63-106 ~]# df -lhT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      xfs        20G   13G  6.9G  65% /
devtmpfs       devtmpfs  916M     0  916M   0% /dev
tmpfs          tmpfs     921M     0  921M   0% /dev/shm
tmpfs          tmpfs     921M   89M  832M  10% /run
tmpfs          tmpfs     921M     0  921M   0% /sys/fs/cgroup
/dev/vdb       xfs       100G   33M  100G   1% /data

Original source: http://blog.chinaunix.net/uid-20788636-id-4988546.html

The second way:
before installing docker
cd /edx
mkdir docker
ln -s /edx/docker/ /var/lib/


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326980452&siteId=291194637