1. Introduction to Docker Volume
What is a Docker Volume?
- A volume is a directory inside a container used for persistent storage.
- It allows data sharing between multiple containers and between a host system and a container.
- Unlike bind mounts, volumes are managed by Docker and stored in Docker’s storage directory (
/var/lib/docker/volumes
).
Key Features of Docker Volumes
- Volumes exist independent of containers, even if we stop container, still we can access volume.
- Firstly, we have to declare this directory as a volume and then share volume
- Volume will be created in one container.
- You can declare a directory as a volume only while creating container.
- If a container is deleted, its volume remains unless explicitly removed.
- Volumes can be shared between multiple containers.
- Volumes do not get included when updating an image.
- You cannot create a volume from an existing container.
- Two ways to map a volume:
- Container ↔ Container
- Host ↔ Container
Benefits of Using Docker Volumes
✅ Decouples storage from containers.
✅ Enables data persistence even after container deletion.