Volume and Container File Operations
Copy files out of a running container
Without a shared volume:
docker cp <container>:/path/in/container ./local-pathVolume ownership mismatch debugging
Symptom: a container’s mounted volume has the wrong owning UID/GID, and
a manual chown fix doesn’t stick across restarts/rebuilds — usually
means either a stale duplicate volume, or something (an
initializeCommand/entrypoint) re-running and resetting ownership after
your fix.
# 1. Confirm there isn't a second/stale volume with a similar name
docker volume ls
# 2. Confirm which actual volume a running container has mounted
docker inspect $(docker ps -q --filter volume=pi-workspace) | grep -A5 Mounts
# 3. Fix ownership directly against the volume, without needing the target
# container running or shelled into — mounts the named volume into a
# throwaway alpine container
docker run --rm -v pi-workspace:/data alpine chown -R 501:20 /data
# 4. Confirm the host UID:GID you actually want to match (needed when a
# container's internal user doesn't line up with your host user, e.g.
# macOS UID 501 vs a container defaulting to 1000)
echo "$(id -u):$(id -g)"If the fix doesn’t survive a rebuild, the likely cause is an
initializeCommand (or equivalent) running the chown, then something
else re-creating/resetting the volume after it — check ordering, not
just presence, of ownership-fixing steps in the container lifecycle.