79718460

Date: 2025-07-29 10:40:05
Score: 0.5
Natty:
Report link

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
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Vince