Running as a host user within a Docker container

后端 未结 3 938
抹茶落季
抹茶落季 2021-02-03 23:58

In my team we use Docker containers to locally run our website applications while we do development on them.

Assuming I\'m working on a Flask app at app.py

3条回答
  •  春和景丽
    2021-02-04 00:43

    You can share the host's passwd file:

    docker run -ti -v /etc/passwd:/etc/passwd -u `id -u`:`id -g` -v `pwd`:`pwd` -w `pwd` -v pydeps:/usr/local -p 8000:8000 python:3-slim ./manage.py runserver
    

    Or, add the user to the image with useradd, using /etc as volume, in the same way you use /usr/local:

    docker run -v etcvol:/etc python..... useradd -u `id -u` $USER
    

    (Both id -u and $USER are resolved in the host shell, before docker receive the command)

提交回复
热议问题