How to increase docker container disk size (devicemapper)

How to increase docker container disk size (devicemapper)

Inside the docker container check the available disk space and get the path to the partition:

root@server2:~# docker exec stefan df -h /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc   20G  1.2G   19G   6% /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc

Current allocated disk size for the container is 20GB and path is: /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc

In the following commands we will increase the size to 50GB.


1.) Calculate the number of blocks in 50GB:

root@server2:~# echo $((50*1024*1024*1024/512))
104857600

2.) Write the dmtable:

root@server2:~# dmsetup table docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc

0 41943040 thin 253:0 218

root@server2:~# echo 0 104857600 thin 253:0 218 | sudo dmsetup load docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
root@server2:~# sudo dmsetup resume docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
root@server2:~# sudo dmsetup table docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc

0 104857600 thin 253:0 216
root@server2:~# xfs_growfs /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
meta-data=/dev/mapper/docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc isize=512    agcount=32, agsize=163840 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=5242880, imaxpct=25
         =                       sunit=16     swidth=16 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=16 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242880 to 13107200

3.) Finally, lets check the size again:

root@server2:~# docker exec stefan df -h /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-252:1-791489-bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc   50G  1.4G   49G   3% /var/lib/docker/devicemapper/mnt/bddbf234169773b6d6b52529ff32572add386085bc248a0ee807f70ce7c00adc
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.