Interview Prep/Docker/Volumes, storage and data

How do you seed a new volume with initial data from an image?

BeginnerScenarioVolumes, storage and data
Answer

Situation read → Docker populates an empty named volume from the image content at the mount path on first use.

What I'd do → Put seed data at the path in the image, then docker run -v seed:/usr/share/app/data app. For databases use /docker-entrypoint-initdb.d/*.sql scripts which run only when the data directory is empty.

Why → Population happens only for an empty named volume, not for bind mounts, which mask image content.

Interview tip → A bind mount over a populated path hides the image's files.

All Docker questions Roadmap: Docker & containers

More on Volumes, storage and data