The default space for the Docker container is 10G, and if you want to specify the size of the default container (specified when you start the container), You can specify it in the Docker configuration file via the Dm.basesize parameter, such as
docker-d--storage-opt dm.basesize=20g
is to specify a default size of 20G, the specific parameters can refer to Https://github.com/docker/docker/tree/master/daemon/graphdriver/devmapper
The above method is just the time to actually build the container, and after the modification needs to restart Docker, unable to dynamically specify the size of the running container, let me explain how to dynamically expand the size of the container space.
Benefits of Dynamic Scaling:
1, do not need to modify the Docker configuration, and restart the Docker service;
2, can be directly to the operation of the container dynamic expansion (can only increase, can not be shrunk);
Disadvantages:
1. The format of Docker host partition must be ext2, ext3, Ext4;
2. The Docker storage engine must be devicemapper
Storage Engine view, you can use Docker info to view
15:25:49 # docker Infocontainers:5images:62storage driver:devicemapper Pool name:docker-8:17-37748738-pool Data file: /data1/docker/devicemapper/devicemapper/data Metadata file:/data1/docker/devicemapper/devicemapper/metadata data Space used:21498.9 MB Data Space total:102400.0 MB Metadata Space used:13.7 MB Metadata Space total:2048.0 mbexecution Driver:lxc-1.0.6kernel version:3.10.0-123.el7.x86_64
From the storage driver above you can see the engine I'm using.
The following is an example of a dynamic extension:
1. Create a new test Container
15:23:48 # docker run --privileged -d -p 22 --name= ' Test ' docker.ops-chukong.com:5000/centos6-http:new /usr/bin/ Supervisord1716fe941926dbd0b247b85d73e83b9465322a5005edc3c6182b59a6ac0939a7[email protected]:/tmp15:24:01 # docker inspect test|grep -i add "IPAddress": "172.17.0.18", [email protected]:/tmp15:24:08 # ssh 172.17.0.18the authenticity of host ' 172.17.0.18 (172.17.0.18) ' can ' t be established . rsa key fingerprint is 39:7c:13:9f:d4:b0:d7:63:fc:ff:ae:e3:46:a4:bf:6b. are you sure you want to continue connecting (yes/no)? yesWarning : permanently added ' 172.17.0.18 ' (RSA) to the list of known hosts. [email protected] ' s password:last login: mon nov 17 14:10:39 2014 from 172.17.42.1[email protected]:~15:24:13 # df - Htfilesystem type size Used Avail Use% Mounted onrootfs rootfs 9.8G 470M 8.8G 5% //dev/mapper/docker-8 :17-37748738-1716fe941926dbd0b247b85d73e83b9465322a5005edc3c6182b59a6ac0939a7 ext4 9.8G 470M 8.8G 5% /shm tmpfs 64m 0 64m 0% /dev/shm/dev/sdb1 ext4 1.8t 30G 1.7T 2% /.dockerinit/dev/sda3 ext4 518G 30G 462G 6% /etc/resolv.conf/dev/sdb1 ext4 1.8T 30G 1.7T 2% /etc/hostname/dev/sdb1 ext4 1.8t 30g 1.7t 2% /etc/hosts/dev/ sdb1 ext4 1.8t 30g 1.7t 2% /.dockerenv
You can see that the root partition where I run the Test container is the EXT4 partition, the container is 10G
2. Use my script to dynamically expand container space
Script Content
15:22:12 # cat dynamic_modify_docker_disk.sh#!/bin/bash#this script is dynamic  MODIFY DOCKER CONTAINER DISK#AUTHOR DENG LEIIF [ -Z $1 ] | | [ -z $2 ]; then echo "usage: container_name Increase_capacity " echo " example: i want increase 11g to test " echo " the command is: sh ' basename $0 ' test 11 ' exit 1 fiif [ ' docker inspect $1 &>>/dev/null && echo 0 | | echo 1 ' -eq 1 ];then echo ' the container $1 is no exist! " Exit 1ficontainer_id= ' docker inspect -f ' {{ . ID&NBSP}} ' $1 ' now_disk= ' dmsetup table /dev/mapper/docker-*-$container _id|awk ' {print $2} ' disk=$ (($2*1024*1024*1024/512)) if [ $disk -lt $now _disk ];then echo "I can ' t shink container $1 from $ ($now _disk*512/1024/ 1024/1024)) g to ${2}g! i only modify contanier increase disk! " exit 1fidmsetup table /dev/mapper/docker-*-$container _id|sed "s/0 [0-9]* thin/0 $disk thin/"|dmsetup load /dev/mapper/docker-*-$container _iddmsetup resume /dev /mapper/docker-*-$container _idresize2fs /dev/mapper/docker-*-$container _idif [ $? -eq 0 ];then echo "Dynamic container $1 disk to ${2}g is success!" else echo "Dynamic container $1 disk to ${2}g is fail! " Fi
Currently adding 20G space dynamically to the Test container
15:24:40 # sh dynamic_modify_docker_disk.sh test 20dynamic container test disk to 20g is success! [email protected]:/tmp15:24:46 # ssh 172.17.0.18[email protected] ' S password: last login: tue jan 20 15:24:13 2015 from 172.17.42.1[email protected]:~15:24:52 # df -htfilesystem type size used avail use% mounted onrootfs rootfs 20g 475m 19g 3% //dev/mapper/docker-8 :17-37748738-1716fe941926dbd0b247b85d73e83b9465322a5005edc3c6182b59a6ac0939a7 ext4 20g 475m 19g 3% /shm tmpfs 64m 0 64m 0% /dev/shm/ dev/sdb1 ext4 1.8t 30g 1.7t 2% /.dockerinit/dev/sda3 ext4 518g 30g 462G 6% /etc/resolv.conf/dev/sdb1 ext4 1.8T 30G 1.7T 2% /etc/hostname/dev/sdb1 ext4 1.8t 30g 1.7t 2% /etc/hosts/dev/sdb1 ext4 1.8T 30G 1.7t 2% /.dockerenv
You can see that you've added success
The following is added to the test to 50G
15:25:21 # sh dynamic_modify_docker_disk.sh test 50dynamic container test disk to 50g is success! [email protected]:/tmp15:25:24 # ssh 172.17.0.18[email protected] ' S password: last login: tue jan 20 15:24:52 2015 from 172.17.42.1[email protected]:~15:25:27 # df -htfilesystem type size used avail use% mounted onrootfs rootfs 50g 480m 47g 1% //dev/mapper/docker-8 :17-37748738-1716fe941926dbd0b247b85d73e83b9465322a5005edc3c6182b59a6ac0939a7 ext4 50g 480m 47g 1% /shm tmpfs 64m 0 64m 0% /dev/shm/ dev/sdb1 ext4 1.8t 30g 1.7t 2% /.dockerinit/dev/sda3 ext4 518g 30g 462G 6% /etc/resolv.conf/dev/sdb1 ext4 1.8T 30G 1.7T 2% /etc/hostname/dev/sdb1 ext4 1.8t 30g 1.7t 2% /etc/hosts/dev/sdb1 ext4 1.8T 30G 1.7t 2% /.dockerenv
can also increase success
But if I shrink to 30G,
15:25:45 # sh dynamic_modify_docker_disk.sh test 30I can ' t shink container test from 50G to 30g! I only modify Contanier increase disk!
is not scaled down and can only be added to the operation.
As for the principle of dynamic increase, please refer to http://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/
FAQ:
When using Docker in CentOS 7, the default storage engine is Devicemapper
When you dynamically resize the Docker container disk space, it appears
RESIZE2FS 1.42.9 (28-dec-2013) Resize2fs:device or resource busy while trying to open/dev/mapper/docker-253:1-1270544-d2 D2cef71c86910467c1afdeb79c1a008552f3f9ef9507bb1e04d77f2ad5eac4couldn ' t find valid filesystem superblock.
The reason is that RESIZE2FS only supports ext2, ext3, Ext4, and does not support XFS
Therefore, it is recommended that the file system format of the Docker server be adjusted to EXT4
This article is from the "Yin-Technical Exchange" blog, please be sure to keep this source http://dl528888.blog.51cto.com/2382721/1606170
Dynamic expansion of container space size for Docker advanced applications