3

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.

ptr
  • 3,292
  • 2
  • 24
  • 48
  • 1
    Question: Is it possible for dumpdata to output to STDOUT? If so, just redirect the result of `docker-compose -f dev.yml run django python manage.py dumpdata > data.json` to a file on your host machine instead of saving it in the container. – trey-jones Jun 02 '16 at 12:40
  • This would work for dumping data like you suggest, yes. so there's that! migration files are created by the django manage.py command sadly. It's looking like there's no easy way to achieve this, and with it being an uncommon use-case a CHOWN after the files are created might have to do. – ptr Jun 13 '16 at 08:27

0 Answers0