Docker is an Opensource Containerization application that will enable you to separate applications with dependencies from the infrastructure. We can say an Infrastructure as an application. Such containers run an entire application in a container, but this can be stopped and restarted at any time. We might lose the data of the application after the restart of the container. But, just like VMs/Compute Engines in Cloud Platforms, we have the option to attach some storage points with the docker containers using Docker Volume and Mount Binds. In this article, we will discuss the difference between Docker Volume vs Bind Mounts vs tmpfs mount
Table of Contents
Data Management in Docker
As we know docker containers are the small application running on top of the operating system. Which might lose the data created or managed by the container if it no longer exists.
For example,
Let’s see how these are working one by one.
Docker Volume
Volumes are part of the Host filesystem. For example, /var/lib/jenkins
is the location that is shared with the docker container, and this location will act as the persistent data in the docker container. Remember this is isolated from the host machine to modify.
These Docker volumes can be created by command docker volume create command. Or this can be created when a container is created at any means like Dockerfile or Docker compose or docker command line. Example, --mount type=volume,src=volumename,dst=/container/path
Bind Mounts
Bind Mounts can be attached at any point at the file system or any disk which can already be used by the Host machine and can be modified from both containers and from the Host. But the limitation with the Bind Mounts are you cannot use the Docker CLI to manage Bind Mounts
You can use --mount type=bind,source=/host/path/,target=/container/path
to configure the Bind Mounts. Remember, Docker container can modify the file system attached with it and can be harmful if we misuse the containers
Tmpfs Mounts
tmpfs mounts is not the persistent data on the disk. It will be available persistent on Neither Host nor Container filesystem.
You can create the mount by using --mount type=tmpfs,destination=/app.
To create tmpfs mounts, you don’t have to create a file structure in your host file system. You can mention only the destination file path and it will create the directory structure on its own.
Conclusion
Docker is one of the heroes saving many business issues in the real-time infrastructure and application environment. Right from creating executor in the built environment to creating entire Operational and Application Infrastructure, Docker plays a vital role. Along with the features, docker offers multiple options to manipulate and use according to our requirements. Hence, we discussed the different options to mount, Docker Volume vs Bind Mounts vs tmpfs mount. Stay tuned and subscribe DigitalVarys for more articles and study materials on DevOps, Agile, DevSecOps and App Development.
Certified Cloud Automation Architect and DevSecOps expert, skilled in optimizing IT workflows with Six Sigma and Value Stream Management. Proficient in both technical and leadership roles, I deliver robust solutions and lead teams to success.