Lesson 13 / 26
Volumes vs Bind Mounts
Two ways to persist and share data outside a container's lifecycle.
Two mechanisms
A volume is storage managed entirely by Docker (best for production data). A bind mount maps a specific folder from your host machine into the container — great for local development.
A practical example
Give a database a named volume so its data survives container removal; bind-mount your source code so edits show up live.
docker volume create pgdata
docker run -d --name db -v pgdata:/var/lib/postgresql/data postgres:16
# bind mount for live-editing source code
docker run -d -v $(pwd)/src:/app/src my-app:1.0