網頁

2015年9月27日 星期日

Docker 1.7.1 --- How to change the docker image installation directory in Ubuntu/Lubuntu 15.04

In general, the Docker will put all the data including images under /var/lib/docker after install the Docker package. It is easy to get the space problem so that need to move the docker default location to new place.  That is to mount docker default location /var/lib/docker to new mount point.
How to do it?

At first, we will prepare the new block storage for planning the moved docker folder
  1. Add a new disk about 20GB
# sudo fdisk -l
AS-IS
TO-BE
  1. Create a new partition by using the sudo fdisk /dev/sd?  
  1. with g option for creating a new empty GPT partition table
  1. with n option for adding a new partition
  1. with p option for printing the partition table and with w option for writing table to disk and exit

  1. Format the new block storage device with ext4 file system
# sudo mkfs.ext4 /dev/sd??

  1. Mount the new block storage device
    1. create a mount point
# sudo mkdir -p /mnt/diskX
    1. mount the file or do equivalent mount in /etc/fstab
# sudo mount -o bind /dev/sd?? /mnt/diskX
    1. create a new folder to house docker
# sudo mkdir /mnt/diskX/docker
# sudo chmod 700 /mnt/diskX/docker

When the new space is ready and mounted, we will move the docker image from the the original path to the new path.
How to do it?
  1. In Ubuntu/Lubuntu 15.04, check out system-wide information
# sudo docker info

  1. In Ubuntu/Lubuntu 15.04, stop containers and docker daemon
# sudo docker ps -q | xargs docker kill

# sudo service docker stop

  1. In Ubuntu/Lubuntu 15.04, if it exists /var/lib/docker/aufs/mnt
# sudo -s
# cd /var/lib/docker/aufs/mnt
# umount ./*
# exit

  1. In Ubuntu/Lubuntu 15.04, move /var/lib/docker to the new mounted storage device
# sudo -s
# mv /var/lib/docker/* /mnt/diskX/docker/
# exit

  1. In Ubuntu/Lubuntu 15.04, set the flag in /etc/default/docker & /etc/init.d/docker to
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 -g /mnt/diskX/docker"
/etc/default/docker

/etc/init.d/docker

  1. In Ubuntu/Lubuntu 15.04, bind mount instead of linking
# sudo mount -o bind /mnt/diskX/docker /var/lib/docker

  1. In Ubuntu/Lubuntu 15.04, periste on restart about mount new disk and bind mount by editing /etc/fstab file and adding the following content:
UUID /mnt/diskX ext4 defaults 0 0
/mnt/diskX/docker /var/lib/docker bind defaults,bind 0 0

  1. In Ubuntu/Lubuntu 15.04, restart docker daemon by using the sudo service docker start command

  1. test that when you create a container the hash appears in /mnt/diskX/docker/containers
After finishing the above step and starting a container, the available space will be extended now.
AS-IS
TO-BE


沒有留言:

張貼留言

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.