Containers with Volumes
Explore the use of Docker volumes to handle persistent data that remains even after container deletion. Learn to create, inspect, and manage volumes, understand how volumes support data sharing across multiple containers and hosts, and discover alternate methods to deploy volumes including usage in Dockerfiles.
Containers and persistent data
There are three main reasons you should use volumes to handle persistent data in containers:
Volumes are independent objects that are not tied to the life cycle of a container.
You can map volumes to specialized external storage systems.
Multiple containers on different Docker hosts can use volumes to access and share the same data.
At a high level, you create a volume, then create a container, and finally mount the volume into the container. When you mount it into the volume, you mount it into a directory in the container’s filesystem, and anything you write to that directory gets stored in the volume. If you delete the container, the volume and data will still exist. You’ll even be able to mount the surviving volume into another container.
The figure above shows a Docker volume outside the container as a separate object. The volume is mounted into the container’s ...