By default all files created inside a container are stored on a writable container layer. This means that:
When the container no longer exists the data is lost, and if another process requires it, it may be challenging to extract the data from the container.
The writable layer of a container is closely tied to the host computer on which it is running. The data cannot be moved simply to another location.
Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.
Volumes and bind mounts are two options provided by Docker for containers to store files on the host machine so that the files are persisted even after the container terminates.
Additionally, Docker supports containers storing files in-memory on the host machine. These files are not kept around. Tmpfs mount is used to store files in the host's system memory if Docker is running on Linux. The named pipe is used by Docker on Windows to store files in the host's system memory.
Selecting the appropriate mount type -
The data appears the same from inside the container regardless of the mount type you employ. In the filesystem of the container, it is exposed as either a directory or an individual file.
Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker.
Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.
tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.
named pipes (npipe) mount can be used for communication between the Docker host and a container. Common use case is to run a third-party tool inside of a container and connect to the Docker Engine API using a named pipe.
With this I'll conclude the post here. We will discuss more about these mount types and it's use cases in the following blogs.
Thank you for reading!
*** Explore | Share | Grow ***
Comments