[Request]: Named volume pre-population from container image
Feature or enhancement request details
When you mount an empty named volume to a container directory (like -v my_volume:/data), container run should automatically copy any existing files from that directory in the image into the volume on first use.
$ echo -e "FROM alpine\nRUN mkdir /xyz && touch /xyz/hello" > Dockerfile
$ container build -t myimage .
$ container run myimage ls -al /xyz/hello
-rw-r--r-- 1 root root 0 Oct 7 00:36 /xyz/hello
$ container v create xyz
xyz
$ container run -v xyz:/xyz myimage ls -al /xyz/hello
ls: /xyz/hello: No such file or directory
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
For reference, this is the desired functionality.
https://docs.docker.com/engine/storage/volumes/#mounting-a-volume-over-existing-data
Closing, thanks @skaegi!
@katiewasnothere I don't see a reason for closing this? My comment was there to provide a reference to the behavior that @skaegi called out.
Reopening this as it relates to another volume-related feature.
Sorry about that! Closing this was an error on my part.
Commenting to follow this one as my ticket #745 was closed in favour of this one :)
Named volumes and non-root images: ownership as well as contents
Adding a data point to this issue (and #745, closed as its duplicate): beyond pre-populating contents, the ownership of a fresh named volume is what breaks most non-root images today.
On container 1.5.0 a named volume is a freshly formatted ext4 filesystem whose root is owned by 0:0, mode 0755, and nothing from the image is copied in. An image that runs as a non-root user therefore can't write to its own data directory once a volume is mounted there.
Tested on a Mac Studio (Apple silicon, macOS 27, container 1.5.0), each with a fresh named volume at the image's data path:
| Image | Runs as (UID:GID) | Mount path | Result |
|---|---|---|---|
docker.io/grafana/grafana:13.2.3 |
472:0 | /var/lib/grafana |
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied |
docker.io/prom/prometheus:v3.15.0 |
65534:65534 | /prometheus |
open /prometheus/queries.active: permission denied |
docker.io/grafana/loki:3.7.8 |
10001:10001 | /loki |
mkdir /loki/rules: permission denied |
docker.io/dpage/pgadmin4:9.18.0 |
5050:0 | /var/lib/pgadmin |
cannot write to /var/lib/pgadmin |
quay.io/jupyter/datascience-notebook:2026-10-12 |
1000:100 | /home/jovyan/work |
cannot write to /home/jovyan/work |
Reproduction:
container volume create grafana-data
container run --rm -v grafana-data:/var/lib/grafana docker.io/grafana/grafana:13.2.3
# mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
Workaround (confirmed — Grafana then starts and /api/health returns 200): chown only the mount root, once, from a root helper:
container run --rm -v grafana-data:/mnt docker.io/library/busybox:1.37 chown 472:0 /mnt
It works, but every tool has to know each image's UID:GID and run an extra VM before the real one.
Docker avoids this by copying the image directory — contents and ownership — into an empty volume on first mount (docs).
Two things that would help, either on its own:
- An owner for a new volume, e.g.
container volume create --uid 472 --gid 0 grafana-data(or--opt uid=,gid=on the local driver). - Optional Docker-compatible population of an empty volume from the image's mount path on first use, preserving ownership and modes.
@melonfleet excellent summary 🫡