stackoverflower
stackoverflower

Reputation: 4063

How does docker map host partitions?

I'm relatively new to docker, and when I started a container (an ubuntu base image), I noticed the following:

On the host,

$ df -h
...
/dev/sdc1       180M   98M   70M  59% /boot
/dev/sdc2        46G   20G   24G  46% /home
/dev/sdc5        37G  7.7G   27G  23% /usr
/dev/sdc6        19G   13G  5.3G  70% /var

$ lsblk
...
sdc      8:32   0 232.9G  0 disk 
├─sdc1   8:33   0   190M  0 part /boot
├─sdc2   8:34   0  46.6G  0 part /home
├─sdc3   8:35   0  18.6G  0 part /
├─sdc4   8:36   0     1K  0 part 
├─sdc5   8:37   0  37.3G  0 part /usr
├─sdc6   8:38   0  18.6G  0 part /var
├─sdc7   8:39   0  29.8G  0 part [SWAP]
└─sdc8   8:40   0  42.8G  0 part 

On the container

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           19G   13G  5.3G  70% /
none             19G   13G  5.3G  70% /
tmpfs           7.8G     0  7.8G   0% /dev
shm              64M     0   64M   0% /dev/shm
/dev/sdc6        19G   13G  5.3G  70% /etc/hosts
tmpfs           7.8G     0  7.8G   0% /proc/kcore
tmpfs           7.8G     0  7.8G   0% /proc/latency_stats
tmpfs           7.8G     0  7.8G   0% /proc/timer_stats

$ lsblk
sdc      8:32   0 232.9G  0 disk 
|-sdc1   8:33   0   190M  0 part 
|-sdc2   8:34   0  46.6G  0 part 
|-sdc3   8:35   0  18.6G  0 part 
|-sdc4   8:36   0     1K  0 part 
|-sdc5   8:37   0  37.3G  0 part 
|-sdc6   8:38   0  18.6G  0 part /var/lib/cassandra
|-sdc7   8:39   0  29.8G  0 part [SWAP]
`-sdc8   8:40   0  42.8G  0 part 

Question 1: why is sdc6 mounted on different places between the host and the container?

Because the contents of the two mount points are different, so I assume docker must have done some kind of device mapping on the container, so sdc6 in the container isn't the same as the one on the host. However, the partition capacity and usage are the same, so I'm confused here.

Question 2: why is the container's root dir usage so high? The docker image doesn't have much stuff on it.

Thanks for any help.

Addition

The Dockerfile has a line

VOLUME /var/lib/cassandra

Upvotes: 3

Views: 2465

Answers (1)

larsks
larsks

Reputation: 312370

Question 1: why is sdc6 mounted on different places between the host and the container?

/dev/sdc6 on your host is /var, which is where /var/lib/docker resides and where Docker keeps certain data, such as the hosts file allocated to your container.

The hosts file is exposed as a bind mount inside the container, which is why you see:

/dev/sdc6        19G   13G  5.3G  70% /etc/hosts

Question 2: why is the container's root dir usage so high? The docker image doesn't have much stuff on it.

Take a look at the df output inside the container:

rootfs           19G   13G  5.3G  70% /

Now look at the df output on your host, and you'll see:

/dev/sdc6        19G   13G  5.3G  70% /var

The df inside the container is reflecting the state of the host filesystem. This suggests that you are using the aufs or overlay storage driver, both of which create "overlay" filesystems for containers on top of the host filesystem. The output from df would look different if you were using the devicemapper storage driver, relies on device mapper block devices instead of overlay filesystems.

Upvotes: 3

Related Questions