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.
More on Volumes, storage and data
A Postgres container was removed and the data is gone. How should it have been run?BeginnerBind mount or named volume for local development of a Node app?BeginnerHow do you back up a named volume?IntermediateTwo containers must share files. What are your options?BeginnerA container needs a writable temp area but the root filesystem is read-only.IntermediateMoving a database volume from one Docker host to another.Intermediate