0

Here is a simple dummy docker-compose :

version: '2.4'
services:
  webserver:
    image: "webserver:latest" // apache, nginx, caddy, whatever
  volumes:
    - "shared_storage:/app/storage/shared"

  analyser:
    image: "custom:latest" // any custom script doing stuff on a volume
  volumes:
    - "shared_storage:/local/storage/shared"

volumes:
  shared_storage

The problem is, the shared_storage is mounted as own by root with rights 644 (or any user I can set using user:) but the webserver is internally running as www-data user (whose I cannot know the id in advance). How can I grant the webserver the access to the shared_storage volume ?

Cheers

  • 1
    Does this answer your question? [Understanding user file ownership in docker: how to avoid changing permissions of linked volumes](https://stackoverflow.com/questions/26500270/understanding-user-file-ownership-in-docker-how-to-avoid-changing-permissions-o) – Dorin Botan Aug 16 '22 at 15:47
  • Ok, I read those resources and endedup with a solution. Ty vm Dorin – bloodycheri Aug 16 '22 at 17:15

1 Answers1

1

Ok, I read dorin's resources and ended up with this working file:

version: '2.4'
services:
  grant:
    image: "webserver:latest" // apache, nginx, caddy, whatever
    volumes:
      - "shared_storage:/app/storage/shared"
    entrypoint: "bin/chown"
    command: ["www-data:www-data", "/app/storage/shared"]
  
  webserver:
    image: "webserver:latest" // apache, nginx, caddy, whatever
    depends_on: grant
    volumes:
      - "shared_storage:/app/storage/shared"

  analyser:
    image: "custom:latest" // any custom script doing stuff on a volume
    volumes:
      - "shared_storage:/local/storage/shared"

volumes:
  shared_storage