4

General question about the internals of Docker and containers running in Kubernetes when using the Docker engine.

Docker containers are ephemeral, meaning that if a container is destroyed, any data that was written to the internals of that container is gone. This leads me to my question:

If one starts a container containing an application which writes a file to a directory that is not backed by a volume, to where does said file actually get written? Is it actually written to disk? Is it actually written to main memory and then just flushed to disk once docker stop occurs? Is it something else?

Same question(s) for a Docker container that is a pod running in Kubernetes. Are the mechanics the same?

John Stone
  • 43
  • 3

1 Answers1

2

Docker data is only kept in host memory for "tmpfs mounts". You may read about how to create such mounts in the article Use tmpfs mounts.

All other non-persistent data is is kept in the writable layer of the container, which is an entire file-system managed by the storage driver. This data doesn’t persist after the container is deleted (but does persist if it is only suspended or stopped), and both read and write speeds are lower than native file system performance, since they pass through the storage driver before passing to the host disk driver.

More than one storage driver are available for Docker, as described in the article Docker storage drivers.

It is not specified in the documentation where the writable layer of a container is stored on the disk, probably in order to let each implementation of a storage driver the freedom of making the best choice.

To see what storage driver your Docker engine is using, run:

$ sudo docker info

If you’re using the Docker default storage driver, you may see something like this:

enter image description here

Using the above information, my guess would be that the writable layers of all containers would be stored under the folder /var/lib/docker/aufs, where aufs stands for the storage driver used (but this is only a guess).

harrymc
  • 455,459
  • 31
  • 526
  • 924