Stories, essays, learning, and other considerations
By Jehan

Things I forget with docker

Explore the filesystem of a stopped container [aufs storage driver]

Note: tested on docker 18.03.1-ce

Once a container is stopped, it’s not possible to exec in the container any more to check the files in it.

When access to those files are needed, find the folder where docker stores them on the file system can be very useful.

With aufs, the following files describe the container’s file system:

1
2
./image/aufs/layerdb/mounts/<Container-ID>/init-id
./image/aufs/layerdb/mounts/<Container-ID>/mount-id

They both contain a reference, the second will contain a mount-id used in those two folders:

1
2
./aufs/diff/<mount-id>/
./aufs/mnt/<mount-id>/

The second I believe contains the filesystem of the container, aggregating all the layers included the changes that happened since the container was started.

The first contains only the changes that happened since the container was started.

So, If one wants access to the changed files of a container, here is a command that puts you in the right folder:

1
2
3
4
5
6
7
# run as root
export CONTAINER_NAME="mycontainer"

cd "/var/lib/docker/aufs/diff/$(\
cat /var/lib/docker/image/aufs/layerdb/mounts/$(\
docker inspect ${CONTAINER_NAME} \
--format {{.Id}})/mount-id)"