Docker Volumes
Last updated
Last updated
Docker containers enable apps to execute in an isolated environment. All modifications made inside the container are lost by default when it ends.
Docker volumes and bind mounts can be useful for storing data in between runs. One way to store data outside of containers is with volumes.
All volumes are kept in a specific directory on your host, typically /var/lib/docker/volumes for Linux systems, and are controlled by Docker.
A Docker container executes the software stack specified in a Docker image.
Images are built up of read-only layers that operate on the Union File System. When we start a new container, Docker adds a read-write layer on top of the image layers, allowing the container to function like a conventional Linux file system.
So, each file modification within the container generates a functioning copy in the read-write layer.
Volume
Docker manages volumes kept in a section of the host filesystem (/var/lib/docker/volumes on Linux).
This portion of the filesystem shouldn’t be altered by non-Docker processes.
In Docker, volumes are the most effective way to store data.
Using the docker volume create command, we may directly create a volume, or Docker can do it for us when it creates a container or service.
Bind Mount
On the host system, bind mounts can be kept anywhere. These might be crucial system folders or files.
They are always modifiable by non-Docker processes running on a Docker host or in a Docker container.
Comparatively speaking, bind mounts are less useful than volumes
Tmpfs Mount
These mounts are never written to the host system’s filesystem; instead, they are kept solely in the memory of the host system.
Neither on the Docker host nor in a container is it stored on a disc.
Sensitive or non-persistent state data can be stored on the tmpfs mount for the duration of the container.
Docker Engine volume plugins link Engine installations with external storage systems such as Amazon EBS, allowing data volumes to survive beyond the lifespan of a single Docker host.