Short answer: 1.6GB
This is an interesting experiment you can perform:
Pull dummy image:
docker pull alpine
Prepare a Dockerfile for a child image alpine
(here I created a 10MB file in the image using dd
)
FROM alpine
RUN dd if=/dev/zero of=file.txt count=10000 bs=1024
Build the child image
docker build -t alpine-plus-ten-mb .
Then inspect the two images and have a look at the layers.
- The lower directory can be read-only or could be an overlay itself.
- The upper directory is normally writable.
- The merged directory is the unified view between upper and lower
- The work directory is used to prepare files as they are switched between the layers.
docker image inspect --format='{{json .GraphDriver.Data}}' alpine
{
"MergedDir": "/var/lib/docker/overlay2/0654e44ddf13ebd2a0feb2ac6261e62f6c83a8be1937a71c544f69eb6208d93b/merged",
"UpperDir": "/var/lib/docker/overlay2/0654e44ddf13ebd2a0feb2ac6261e62f6c83a8be1937a71c544f69eb6208d93b/diff",
"WorkDir": "/var/lib/docker/overlay2/0654e44ddf13ebd2a0feb2ac6261e62f6c83a8be1937a71c544f69eb6208d93b/work"
}
docker image inspect --format='{{json .GraphDriver.Data}}' alpine-plus-ten-mb
{
"LowerDir": "/var/lib/docker/overlay2/0654e44ddf13ebd2a0feb2ac6261e62f6c83a8be1937a71c544f69eb6208d93b/diff",
"MergedDir": "/var/lib/docker/overlay2/5ca936630339967105c28d4d8c9669d99f0f449a307c43c09d60f6341cf56271/merged",
"UpperDir": "/var/lib/docker/overlay2/5ca936630339967105c28d4d8c9669d99f0f449a307c43c09d60f6341cf56271/diff",
"WorkDir": "/var/lib/docker/overlay2/5ca936630339967105c28d4d8c9669d99f0f449a307c43c09d60f6341cf56271/work"
}
Note that the UpperDir
of the base alpine image (...d93b/diff
) appears to be LowerDir
for the derived image alpine-plus-ten-mb
.
One important aspect: the layer ...d93b/diff
is read-only for the child image alpine-plus-ten-mb
. In other words, that layer is guaranteed to be immutable and this allows other derived images to reuse it and build their own deltas on top of it, without duplicating(creating a copy) it.
These can be explored on the host system as well. Here is the ~10MB delta that I artificially added with dd
when I built the child image.
sudo du -sh "/var/lib/docker/overlay2/5ca936630339967105c28d4d8c9669d99f0f449a307c43c09d60f6341cf56271/diff"
9.8M /var/lib/docker/overlay2/5ca936630339967105c28d4d8c9669d99f0f449a307c43c09d60f6341cf56271/diff