What You'll Learn
Beginner
- Why containers lose data when they stop
- How volumes solve the persistence problem
- When to use volumes vs bind mounts
The Problem: Ephemeral Containers
Containers are disposable
When a container is removed, its writable layer is deleted. Any data stored inside is lost forever.The Solution: Volumes
Named volumes (Docker-managed) vs bind mounts (host directory)
Terminalbash
# Create a named volume
docker volume create pg-data
# Mount it
docker run -d -v pg-data:/var/lib/postgresql/data postgres:15Three Storage Options
| Type | Best for |
|---|---|
| Named volume | Databases, app state |
| Bind mount | Source code, config |
| tmpfs | Temporary data, secrets |
Key Takeaways
- <
- c
- o
- d
- e
- >
- d
- o
- c
- k
- e
- r
- v
- o
- l
- u
- m
- e
- c
- r
- e
- a
- t
- e
- /
- l
- s
- /
- i
- n
- s
- p
- e
- c
- t
- /
- r
- m
- <
- /
- c
- o
- d
- e
- >
- .
Previously: Module 3 covered containers.
Today: You learned: Why containers lose data and how volumes fix it.
Next: Lesson 24 compares volumes and bind mounts.
Today: You learned: Why containers lose data and how volumes fix it.
Next: Lesson 24 compares volumes and bind mounts.
Comments
Comments
Post a Comment