Volumes: keeping files around
Why container storage vanishes.
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.
spec:containers:- name: appimage: my-app:1.4volumeMounts: [{ name: scratch, mountPath: /data }] # survives container restart- name: sidecarimage: log-shipper:1.0volumeMounts: [{ name: scratch, mountPath: /shared }] # same files, sharedvolumes:- name: scratchemptyDir: {} # 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.