Chapter 0712 mins • intermediate
Volumes & Data Persistence
Named Volumes vs Bind Mounts & Ephemeral Storage
What You Will Master:
- Understand the ephemeral nature of the container writable layer
- Create and attach Named Volumes with `docker volume create` and `-v`
- Compare Named Volumes vs Host Bind Mounts
1Why Containers are Ephemeral
Any file written inside a container lives in its ephemeral read-write layer. If the container is deleted (docker rm), all modified files and database records inside that layer are permanently destroyed!
To save persistent data, we use Docker Volumes or Bind Mounts.
Interactive Lab
Create and Mount a Persistent Volume
Create a named volume `db-data` and mount it to a postgres database container.
0/2 Steps
Step 1: Create volume named db-data
Run `docker volume create db-data`
Step 2: Run postgres with db-data mounted to /var/lib/postgresql/data
Run `docker run -d --name db -v db-data:/var/lib/postgresql/data postgres:16-alpine`
Chapter Knowledge Quiz
Pass the 3-question assessment to earn +50 XP and complete this chapter.
Sponsor & Resources