Volumes: keeping files around

Why container storage vanishes.

Beginner10 min · lesson 20 of 24
In plain terms
A container’s own disk is a hotel-room whiteboard, wiped at checkout. A volume is a bag you clip onto the pod so your files survive a restart.

A container’s own filesystem is temporary — whatever it writes there vanishes when the container restarts. Volumes are how a pod keeps files around and shares them, and understanding why container storage disappears is the first step to handling any app that needs to remember data.

Why container storage vanishes

When a container restarts, it starts fresh from its image, and anything it had written to its own filesystem is gone — that ephemerality is by design and is fine for stateless apps, but a problem the moment an app needs to keep data. A volume is storage attached at the pod level and mounted into the container, and it lives independently of the container: data in a volume survives a container restart within the pod, and a volume can be shared between containers in the same pod. The simplest kind, emptyDir, is scratch space that is created when the pod starts and lasts as long as the pod — perfect for temporary files or for two containers in a pod to share (like an app writing logs that a sidecar reads). So volumes solve the "the container forgot everything when it restarted" problem, at least for the lifetime of the pod.

a shared scratch volume
spec:
containers:
- name: app
image: my-app:1.4
volumeMounts: [{ name: scratch, mountPath: /data }] # survives container restart
- name: sidecar
image: log-shipper:1.0
volumeMounts: [{ name: scratch, mountPath: /shared }] # same files, shared
volumes:
- name: scratch
emptyDir: {} # lives as long as the POD (gone when the pod is deleted)

The limit — and what comes next

Here is the crucial limit: an emptyDir volume lasts only as long as the pod. When the pod is deleted or replaced (which, remember, happens routinely), the emptyDir and everything in it is gone. So emptyDir is great for temporary and shared data, but it is not how you keep data that must truly persist — a database’s files, uploaded content, anything that must outlive the pod. For that you need persistent storage, which lives outside the pod entirely and survives pods coming and going — that is the very next lesson (PersistentVolumeClaims). There is also another volume type to simply be aware of and avoid as a beginner: hostPath, which mounts a folder from the node itself; it ties the pod to that specific machine and carries security risks, so it is not the answer for ordinary app data. The takeaway to carry forward: container filesystems are throwaway, volumes let a pod keep and share files, emptyDir covers temporary needs within a pod’s life, and truly durable data needs the persistent storage covered next.

Volumes in a pod
what volumes fix
container fs is temporary
wiped on restart
volume survives restart
and can be shared in the pod
the emptyDir limit
lasts as long as the pod
gone when the pod is replaced
durable data → persistent storage
next lesson
Container filesystems are throwaway; volumes let a pod keep and share files. emptyDir covers a pod’s lifetime — data that must outlive the pod needs persistent storage.
emptyDir data disappears when the pod is replaced
An emptyDir volume only lives as long as its pod — and pods are routinely deleted and recreated, so anything important stored there is lost. Use emptyDir for scratch and sharing within a pod, but for data that must survive (databases, uploads) use persistent storage (next lesson), which lives outside the pod. And avoid hostPath for app data — it pins the pod to one node and carries security risks.