Docker container drive does not match available hard drive space on host
I have loaded a new custom image into a remote RedHat 7 docker host instance. When running a new container, the container does not attempt to use the entire disk. I get the following is the output of a df -h on the container:
rootfs 9.8G 9.3G 0 100% / /dev/mapper/docker-253:0-67515990-5700c262a29a5bb39d9747532360bf6a346853b0ab1ca6e5e988d7c8191c2573 9.8G 9.3G 0 100% / tmpfs 1.9G 0 1.9G 0% /dev shm 64M 0 64M 0% /dev/shm /dev/mapper/vg_root-lv_root 49G 25G 25G 51% /etc/resolv.conf /dev/mapper/vg_root-lv_root 49G 25G 25G 51% /etc/hostname /dev/mapper/vg_root-lv_root 49G 25G 25G 51% /etc/hosts tmpfs 1.9G 0 1.9G 0% /proc/kcore tmpfs 1.9G 0 1.9G 0% /proc/timer_stats
But the host system has much more space:
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_root-lv_root 49G 25G 25G 51% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.5M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/vg_root-lv_home 9.8G 73M 9.7G 1% /home /dev/sda1 497M 96M 402M 20% /boot
It seems as if docker is assigning the 9.8 gigs of the /home mapping to the entire drive of the container. So I am wondering if there is a reason I am seeing this?
One Solution collect form web for “Docker container drive does not match available hard drive space on host”
I was able to resolve this problem. The issue was not related to the volume that was being mounted to the container (ie It was not mounting the home volume as the root volume on the container). The problem occurred because docker uses device-mapper in RedHat to manage the file systems of it’s containers. By default, the containers will start with 10G of space. In general, docker will use AUFS to manage the file systems of the containers. This is the case on most Debian based versions of Linux, but RedHat uses device-mapper instead.
Luckily, the device-mapper size is configurable in docker. First, I had to stop my service, and remove all of my images/containers. (NOTE: There is no coming back from this, so backup all images as needed).
sudo service stop docker && sudo rm -irf /var/lib/docker
Then, start up the docker instance manually with the desired size parameters:
sudo docker -d --storage-opt dm.basesize=[DESIRED_SIZE]
In my case, I increased my container size to 13G:
sudo docker -d --storage-opt dm.basesize=13G
Then with docker still running, pull/reload the desired image, start a container, and the size should now match the desired size.
Next, I set my docker systemd service file to startup with the desired container size. This is required so that the docker service will start the containers up with the desired size. I edited the OPTIONS variable in the /etc/sysconfig/docker file. It now looks like this:
OPTIONS='--selinux-enabled --storage-opt dm.basesize=13G'
Finally, restart the docker service:
sudo service stop docker
 https://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/ – This is how I discovered RedHat uses device-mapper, and that device-mapper has a 10G limit.
 https://docs.docker.com/reference/commandline/cli/ – Found the storage options in dockers documentation.