Course contentsShow
← Software Engineering
Lesson 1429 of 1,93342. Containerization and OrchestrationFree lesson

Container Storage and Volumes

Understand ephemeral container storage and how volumes persist data beyond container lifecycle.

Container Storage and Volumes

What You'll Learn

You'll understand why containers lose their data by default and how volumes allow data to persist beyond a container's lifetime.

The Ephemeral Nature of Container Storage

By default, container storage is ephemeral — it disappears when the container stops. Every file you create, every database record you write, every log you generate vanishes the moment that container is removed.

This happens because each container has its own writable layer stacked on top of the read-only image layers you learned about. When the container dies, that writable layer is destroyed.

Analogy: Think of a container like a hotel room. Everything you do during your stay (unmade bed, used towels) disappears when housekeeping cleans after checkout. The room returns to its original state.

Why This Matters

Ephemeral storage is fine for stateless applications, but problematic for:

  • Databases that must persist data
  • Applications generating logs you need to analyze
  • User-uploaded files
  • Configuration that should survive restarts

Volumes: Persistence Beyond the Container

Volumes are the solution. A volume is storage that lives outside the container's lifecycle, managed by the container runtime.

When you attach a volume to a container, you're essentially saying: "Mount this external storage at this path inside my container." The container reads and writes to it like normal filesystem storage, but the data persists even after the container is destroyed.

Volumes can be:

  • Host-mounted: Directories from the host machine mapped into the container
  • Named volumes: Managed by the container runtime, independent of host paths
  • Shared between containers: Multiple containers can access the same volume

Key Takeaway: Containers have ephemeral storage by default — all data is lost when the container stops. Volumes provide persistent storage that survives beyond the container's lifecycle, essential for stateful applications like databases.