Running as a host user within a Docker container

后端 未结 3 936
抹茶落季
抹茶落季 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:50

    Just hit this problem and found a different workaround.

    From getpass.py:

    def getuser():
        """Get the username from the environment or password database.
    
        First try various environment variables, then the password
        database.  This works on Windows as long as USERNAME is set.
    
        """
    
    
        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
            user = os.environ.get(name)
            if user:
                return user
    
    
        # If this fails, the exception will "explain" why
        import pwd
        return pwd.getpwuid(os.getuid())[0]
    

    The call to getpwuid() is only made if none of the following environment variables are set: LOGNAME, USER, LNAME, USERNAME

    Setting any of them should allow the container to start.

    $ docker run -ti -e USER=someuser ...
    

    In my case, the call to getuser() seems to come from the Werkzeug library trying to generate a debugger pin code.

提交回复
热议问题