Containers With Volumes

Learn about Docker volumes, their purpose, and how to create, inspect, and delete them effectively.

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 lifecycle 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.

Get hands-on with 1400+ tech skills courses.