What are Docker volumes and their types?
Noor Ul Qumar
DevOps Engineer @ Tkxel | AWS | GCP | Docker | Kubernetes | ArgoCD | Linux | Ansible | Scripting | CICD | IAC
What are Docker volumes and their types?
Docker volumes are used for data persistence in Docker. So if we have a database or state full application, we would like to use data volumes.
Container has Virtual File System and Host has Physical File System. Using volumes, we plug the Physical File System path (folder/directory) into the container's Virtual File System path.
In simple terms, a folder/directory in the Physical File System is MOUNTED into the Virtual File System of the Container.
Use cases of Docker Volumes: -
Let's say we have a database container, which is running on the host (EC2 instance), and it has a virtual file system where data is usually stored. But there is no persistence of data. If we remove the container and start a new container, then the data in this virtual file system is gone, and it starts from fresh state, which is not really practical. We need Docker volumes.
By using Docker volumes what happened, is when a container writes to its Virtual File System, it gets replicated or automatically written on the host file system directory (Physical File System), and the same if we change something on the host file system (Physical File System), it automatically appears on the containers Virtual File System as well.
So that is why when a container is restarted, even if it starts from a fresh state its own Virtual File System gets the data automatically from the host file system, because data is still there, and that is how data is populated on the startup of a container every time.
Types of Docker Volumes: -