M
M
maksam072021-01-22 13:10:50
Django
maksam07, 2021-01-22 13:10:50

How to execute the exec command (docker-compose) so that the files created afterwards belong to the current user on the host machine?

Good afternoon!
When executing a command like

docker-compose exec web python manage.py startapp poll

The poll folder is created on the host machine, but it belongs to root and, in fact, I can’t make changes to the files until I change the group and user from root to the current one.
My project is based on these files:
docker-compose.yml: https:/ /github.com/testdrivenio/django-on-docker/b...
Dockerfile: https://github.com/testdrivenio/django-on-docker/b...

Tried options:
- https://medium.com /faun/set-current-host-user-for-...
- https://jtreminio.com/blog/running-docker-containe...
but that didn't solve the problem. Who faced and decided, tell me, please, which option works for you or how do you get out of this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Kuzmichev, 2021-01-22
@maksam07

If you do not specifically give the command you are running and the contents of your specific docker / compose files, then here is the answer corresponding to the question: you have an error somewhere, because it should work.

[email protected]:/tmp/test$ docker container run --rm -v ${PWD}:/tmp -u $(id -u ${USER}):$(id -g ${USER}) ubuntu:18.04 touch /tmp/it.is.my.file
[email protected]:/tmp/test$ ll
итого 20
drwxrwxr-x  2 user user   4096 янв 22 13:55 ./
drwxrwxrwt 23 root root  16384 янв 22 13:55 ../
-rw-r--r--  1 user user      0 янв 22 13:55 it.is.my.file
[email protected]:/tmp/test$ rm it.is.my.file 
[email protected]:/tmp/test$ docker container run --rm -v ${PWD}:/tmp ubuntu:18.04 touch /tmp/it.is.my.file
[email protected]:/tmp/test$ ll
итого 20
drwxrwxr-x  2 user  user   4096 янв 22 14:01 ./
drwxrwxrwt 23 root  root  16384 янв 22 14:01 ../
-rw-r--r--  1 root  root      0 янв 22 14:01 it.is.my.file
[email protected]:/tmp/test$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question