I'm using cookiecutter-django project template which includes nice docker-compose integration. However when I run a manage.py command that creates a file via docker-compose e.g:
sudo docker-compose -f dev.yml run django python manage.py dumpdata --output ./myapp/fixtures/data.json
the file is owned by root:root
so I do not initially have write permissions on my host filesystem. I'm still learning about docker-compose and am struggling to find the tidiest way to chown
any created files back to my local user.
I did try setting the user:
flag in my django service in dev.yml like so..
django:
user: $USER
but this didn't take.
I also read about using
django:
user: ${UID}
but this also fails with a warning
WARNING: The UID variable is not set. Defaulting to a blank string.
despite echo $UID
returning the correct value. So for some reason, env variables are not being passed through properly, though I don't know how to go about debugging that. possibly related: https://github.com/docker/compose/issues/2613
edit: more updates.
so running docker-compose -f dev.yml run django env
shows that $UID isn't present. I tried assigning it in entrypoint.sh
but as that file is run by root, the $UID will be 0 at runtime. I'm out of ideas now as to how to pass the user ID in.