Today, colleagues to install the SDK in the Docker Jenkins container, when he put his previous installation of the SDK to pass me, I found that there are 16g,docker containers are only 10 g, fortunately, let me find a dynamic expansion of the Docker container articles, first to share with you.
System: CentOS 6 (64-bit)
Docker version: 1.7.1
Docker Storage Engine: Devicemapper
The host partition format must be: Ext2, ext3, Ext4
Script content:
#!/bin/bash
#This script is dynamic modify Docker container disk
#Author Deng Lei
If [-Z $] | | [-Z $]; Then
echo "Usage:container_name increase_capacity"
echo "Example:i want increase 11G to test"
echo "The command Is:sh ' basename $ ' Test 11"
Exit 1
Fi
If [' Docker inspect $ &>>/dev/null && echo 0 | |-echo 1 '-eq 1];then
echo "The container is no exist!"
Exit 1
Fi
Container_id= ' Docker inspect-f ' {{. Id}} ' $ '
now_disk= ' dmsetup table/dev/mapper/docker-*-$container _id|awk ' {print $} '
disk=$ (($2*1024*1024*1024/512))
If [$disk-lt $now _disk];then
echo "I can ' t shink container $ (($now _disk*512/1024/1024/1024)) G to ${2}g! I only modify Contanier increase disk! "
Exit 1
Fi
Dmsetup table/dev/mapper/docker-*-$container _id|sed "s/0 [0-9]* thin/0 $disk thin/" |dmsetup load/dev/mapper/docker-*- $container _id
Dmsetup resume/dev/mapper/docker-*-$container _id
resize2fs/dev/mapper/docker-*-$container _id
If [$?-eq 0];then
echo "Dynamic container disk to ${2}g is success!"
Else
echo "Dynamic container disk to ${2}g is fail!"
Fi
I'm turning the space of the Jenkins container up to 30g.
PS: This script can only increase the space of the container, can not be reduced, so please consider the use of a clear. Interested can look at the following article, he spoke in more detail.
The following are examples of dynamic extensions :
1. New Test Container set up
15:23:48 # Docker run--privileged-d-P--name= ' test ' Docker.ops-chukong.com:5000/centos6-http:new/usr/bin/supervis Ord
1716fe941926dbd0b247b85d73e83b9465322a5005edc3c6182b59a6ac0939a7
Root@ip-10-10-27-221:/tmp
15:24:01 # Docker Inspect test|grep-i add
"IPAddress": "172.17.0.18",
Root@ip-10-10-27-221:/tmp
15:24:08 # SSH 172.17.0.18
The 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 your want to continue connecting (yes/no)? Yes
warning:permanently added ' 172.17.0.18 ' (RSA) to the list of known hosts.
root@172.17.0.18 ' s Password:
Last Login:mon Nov 14:10:39 2014 from 172.17.42.1
root@1716fe941926:~
15:24:13 # DF-HT
FileSystem Type Size Used avail use% mounted on
Rootfs 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 I'm running the test container's root partition is the EXT4 partition, the container is 10G
2, use my script to dynamically expand the 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 Lei
If [-Z $] | | [-Z $]; Then
echo "Usage:container_name increase_capacity"
echo "Example:i want increase 11G to test"
echo "The command Is:sh ' basename $ ' Test 11"
Exit 1
Fi
If [' Docker inspect $ &>>/dev/null && echo 0 | |-echo 1 '-eq 1];then
echo "The container is no exist!"
Exit 1
Fi
Container_id= ' Docker inspect-f ' {{. Id}} ' $ '
now_disk= ' dmsetup table/dev/mapper/docker-*-$container _id|awk ' {print $} '
disk=$ (($2*1024*1024*1024/512))
If [$disk-lt $now _disk];then
echo "I can ' t shink container $ (($now _disk*512/1024/1024/1024)) G to ${2}g! I only modify Contanier increase disk! "
Exit 1
Fi
Dmsetup table/dev/mapper/docker-*-$container _id|sed "s/0 [0-9]* thin/0 $disk thin/" |dmsetup load/dev/mapper/docker-*- $container _id
Dmsetup resume/dev/mapper/docker-*-$container _id
resize2fs/dev/mapper/docker-*-$container _id
If [$?-eq 0];then
echo "Dynamic container disk to ${2}g is success!"
Else
echo "Dynamic container disk to ${2}g is fail!"
Fi
Currently adding 20G space to the test container dynamically
15:24:40 # sh dynamic_modify_docker_disk.sh Test 20
Dynamic container test disk to 20G is success!
Root@ip-10-10-27-221:/tmp
15:24:46 # SSH 172.17.0.18
root@172.17.0.18 ' s Password:
Last Login:tue a 15:24:13 2015 from 172.17.42.1
root@1716fe941926:~
15:24:52 # DF-HT
FileSystem Type Size Used avail use% mounted on
Rootfs 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
Can be seen to have increased the success
The following increases to 50G for test
15:25:21 # sh dynamic_modify_docker_disk.sh Test 50
Dynamic container test disk to 50G is success!
Root@ip-10-10-27-221:/tmp
15:25:24 # SSH 172.17.0.18
root@172.17.0.18 ' s Password:
Last Login:tue a 15:24:52 2015 from 172.17.42.1
root@1716fe941926:~
15:25:27 # DF-HT
FileSystem Type Size Used avail use% mounted on
Rootfs 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 the success
But if I shrink to 30G,
15:25:45 # sh dynamic_modify_docker_disk.sh Test 30
I 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 are dynamically adjusting the Docker container disk space, there are
RESIZE2FS 1.42.9 (28-dec-2013)
Resize2fs:device or resource busy while trying to open/dev/mapper/docker-253:1-1270544- D2d2cef71c86910467c1afdeb79c1a008552f3f9ef9507bb1e04d77f2ad5eac4
Couldn ' 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