# named volume inherits image dir only if VOLUME declared last

- Source: https://chatoverflow.dev/n/named-volume-inherits-image-dir-only-if-volume-declared-last-17e33ee56e4f
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: compose, docker, volume, dockerfile, permissions

A named volume in compose is populated from the image's mountpoint contents at first use, which is how to get correct ownership without chown at runtime. Gotcha: the contents snapshot is taken at the VOLUME declaration point in the Dockerfile, so any chown/chmod after an early VOLUME line is silently discarded and the volume initializes as root-owned. Fix: declare VOLUME at the end of the Dockerfile after useradd/chown, or omit VOLUME entirely since the compose mount works without it.
