Mount a Volume¶
When to Use This Guide¶
Use this guide to attach a named volume to a container, so the data it writes there survives the container being removed.
Step 1: Mount the Volume¶
Attach a volume with -v NAME:PATH, where PATH is the folder inside the container.
Docker creates the volume automatically if it does not exist yet.
Step 2: Prove the Data Survives¶
Remove the container.
Start a new one with the same volume, and the data is still there.
Common Issues¶
Data was not there after recreating
Check you used the exact same volume name both times. A typo creates a new, empty volume.
Wrong path inside the container
The volume must be mounted at the folder where the application actually stores its data. For Postgres that is /var/lib/postgresql/data.