Docker is not the new word in IT automation now. Most of the companies are taking benefits of Docker containers and are running their application on it. In this, we are going to explain about different mount types for Docker containers and which you can use in your environment.
As we have not covered Docker earlier, so let’s begin with knowing what is Docker.
What is Docker?
In simple terms, Docker is an open source software that performs operating-system-level virtualization which is also called containerization.
It helps in creating, deploying and managing virtualized application containers on a common operating system (OS). Docker containers are basically, running instances of Docker images and contains the application and its dependencies which are required for running the application.
Currently, Docker supports Linux, Windows and MacOS operating system and is written on “Go” language.
Different Mount Types for Docker Containers
Basically, there are 3 types of mounts which you can use in your Docker container viz. Volumes, Bind mount and tmpfs mounts.
Now, let’s know in detail about these mount options available for Docker containers.
Volumes
These are the most common mount option available for Docker containers and is fully managed by Docker engine. You can create a volume through Docker commands and can share it within the Docker containers.
When you create a volume, it is stored within a directory on the Docker host (/var/lib/docker/volumes/ on Linux) and is completely isolated from Docker host. Multiple Docker containers can use the same volumes and can read-write simultaneously.
When the container is not running, data still persist in volumes.
Bind Mounts
These are the host machine file systems which are mounted on Docker container and this Docker don’t have control over it and host machine only manages it.
When you use a bind mount, a file or directory on the host machine is mounted into a Docker container. Their performance is good, but containers have to rely on the host machine’s filesystem having a specific directory structure available.
tmpfs Mounts
As the name suggests, these mounts are temporary and once the Docker container is stopped the data present on these mounts is also lost.
tmpfs mounts are stored in the host system’s memory only and are never written to the host system’s filesystem and thus does not hold data permanently.
Below image from Docker website shows all these 3 mounts and depicts where the data lives on the Docker host.
Image Courtesy: https://docs.docker.com/
Which Mount Type to Use in Docker Containers
Once you know what are the different types of mounts for Docker containers, we are sure you can decide which one to use.
Volumes can be used if you want your Docker to manage the mount points and data. You can also use this type of mount if the Docker host is not guaranteed to have a given directory or file structure or want to store your container’s data on a remote host or a cloud provider, rather than locally.
Bind mounts can be used if you want to save your data locally on the host itself or want to share data from your Docker host to the Docker container especially, configuration files, source code, etc.
tmpfs mounts are best for sensitive data or information and if you do not want the data to be saved on the host machine or docker container. If you want to store some secret keys you can use tmpfs, just for an example.
Hope, you have enjoyed reading this article on “different types of mount for Docker containers” and if you do, please share this article with your colleague and friends.
If you have any doubts or concern regarding this article, please let us know through your comments and emails. We will be sharing more tutorials on Docker in coming days, so do subscribe to our blog and also follow us on social media.