Files Written to an Unmounted Container Path Live Only in That Container's Layer
A container writes into its own writable layer unless a volume is mounted at the path it writes to. Those files exist only in that container: other containers can't see them, and they disappear when it is recreated. An app that saves to a default path like /downloads, with no volume there, will appear to work while its output is invisible to everything that needs it.
How It Shows Up
In my media stack, a download client finished multi-gigabyte downloads, yet the media manager that should import them saw nothing:
- the download client saved to its default
/downloads, where nothing was mounted, so files landed in the container's own layer; - the media manager only had the shared NFS volume (
/data), so it couldn't reach them; - both apps were healthy and logged success.
Two Rules for Apps That Hand Files to Each Other
- Mount a volume at every path the app writes data to. Check the image's documentation for its default paths;
kubectl exec <pod> -- df -h <path>shows whether a path is a mount or the root layer. - Give cooperating containers the same path for the same files. If the downloader saves to
/data/downloads/movie.mkv, the importer must see that file at/data/downloads/movie.mkvtoo. Different mount points mean the path one app reports doesn't exist for the other, even when both mount the same share.
# both containers mount the same share at the same path
volumeMounts:
- name: media
mountPath: /data
References
- Kubernetes MOC - hub for Kubernetes notes.
- Docker and Container Security MOC - hub for container notes.
- A Container Shares the Host Kernel, a Virtual Machine Runs Its Own - the OverlayFS layers behind the container filesystem.
- Kubernetes Storage Failures Usually Start on the Host or the NAS - the other half of shared-storage troubles.
- Kubernetes documentation: Volumes - why container files are ephemeral without a volume.
Review cards
Flashcard Why do files written to an unmounted container path disappear when the container is recreated?
Files written to the container's writable layer are not persisted outside of that layer and are lost when the container is recreated.
Flashcard A downloader and an importer mount the same share at /downloads and /data. Why can't the importer find /downloads/movie.mkv?
That path only exists in the downloader's container. Cooperating containers must mount the same share at the same path, so a path one reports is valid for the other.