Volumes have permissions root:root
and this has been the default for compose since forever (2016?) https://github.com/docker/compose/issues/3270
If you want to change the ownership you can create a second service that runs as root on startup and changes ownership of the directory in the volume to your user.
Here is an example
services:
# Fix Ownership of Build Directory
# Thanks to Bug in Docker itself we need to use steps like this
# Because by default, the volume directory is owned by Root
change-vol-ownership:
# We can use any image we want as long as we can chown
# Busybox is a good choice
# as it is small and has the required tools
image: busybox:latest
# Need a user priviliged enough to chown
user: "root"
# Specify the group ID of the user in question
group_add:
- '${GROUP_ID}'
# The volume to chown and bind it to container directory /data
volumes:
- my-volume:/app/documents
# Finally change ownership to the user
# example 1000:1000
command: chown -R ${USER_ID}:${GROUP_ID} /app/documents
app:
image: my-image:latest
restart: unless-stopped
volumes:
- my-volume:/app/documents
user: "${USER_ID}:${GROUP_ID}"
depends_on:
change-vol-ownership:
# Wait for the ownership to change
condition: service_completed_successfully