Minimal example of compose.yaml
services:
my_service:
image: alpine
volumes:
- my_vol:/my_vol
command: [sh, -c, 'adduser -S -s /bin/sh my_user && su - my_user -c "mkdir /my_vol/my_folder"']
volumes:
my_vol:
$ docker compose up
[+] Running 2/2
✔ Network tests_default Created
✔ Container tests-my_service-1 Created
Attaching to my_service-1
my_service-1 | mkdir: can't create directory '/my_vol/my_folder': Permission denied
my_service-1 exited with code 1
$
I have a service that relies on a shared volume for persistence (in the real example is also shared between multiple services).
Internally the application needs to write in the volume, but it cannot, as you can see from the error. From what I see the mounted folder has rwxr-xr-x
permission, and the owner is root
, so it cannot be written by my_user
Is there a way to set my_vol
options to make it writable? I found https://docs.docker.com/compose/compose-file/07-volumes/#driver_opts where I could set the volume driver options, but that seems applicable only for bind volumes