Consider the following failing docker-compose.yml:
version: '3.7'
services:
test:
image: ubuntu
user: nobody
entrypoint: touch /tmp-a/hai
volumes:
- a:/tmp-a
volumes:
a:
In the example, in order to avoid creating a Dockerfile, I manually set the user. Normally though, I try to drop root in my Dockerfiles and when I do that, I can't use the volumes docker-compose mounted for me. The reason is that the root directory for that mount is owned by root and any user other than root can't write there.
My workaround is to explicitly set user: root
in docker-compose, then change the permissions manually for the directory and drop the privileges in entrypoint
, but I find that very inelegant. Is there a way to make docker-compose set permissions for my containers so that my test case doesn't fail?