How to change the default images storage location for Docker

Source: Internet
Author: User
Tags rsync

The image of Docker and some data are in the/var/lib/docker directory, it occupies the Linux system partition, that is, the following/dev/vda1, when there are multiple mirrors,/dev/vda1 space may be insufficient, We can attach Docker data to a data disk, for example:/dev/vdb directory.
[Email protected] 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, back up the Fstab file
sudo cp/etc/fstab/etc/fstab.$ (date +%y-%m-%d)
(2) Stop Docker and sync/var/lib/docker to new location with Rsync.
If rsync is not installed, use yum-y intall rsync to install, stop Docker, service Docker stop, create a directory to mount in the data partition, Mkdir/data/docker sync with the Rsync tool, rsync-axs/var/lib/docker/. /data/docker/, this may take a long time, depending on the size of the/var/lib/docker,
(3) Modify Fstab
Add the following line to the Fstab in the file and mount the new location to the/var/lib/docker
/data/docker/var/lib/docker None bind 0 0
Within the file, as follows:
[Email protected] docker]# Cat/etc/fstab
#
#/etc/fstab
# Created by Anaconda on Thu Jul 31 07:50:13 2014
#
# Accessible filesystems, by reference, is maintained under '/dev/disk '
# See mans 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
Before you change the/var/lib/docker path:
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
Partition size information in the host:
[Email protected] ~]# 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

How to change the default images storage location for Docker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.