我试图在Docker容器中不使用root,但是Gunicorn没有启动。
FROM python:2.7
RUN apt update && \
apt install -y python-pip gcc python-dev libpq-dev && \
pip install --upgrade pip && \
pip install gunicorn && \
pip install eventlet && \
pip install psycopg2
RUN addgroup [username_group] && \
useradd -rm -d /home/[home] -s /bin/bash -g [username_group] -G sudo -u 1000 [username] # uid taken from host system
# USER [username] # if this line is un-commented it doesn't work.
COPY ./web2py /home/[home]/web2py
WORKDIR /home/[home]/web2py
EXPOSE 80 443
CMD gunicorn -b 0.0.0.0:80 -w 3 wsgihandler
这是输出
[container] | [2019-01-28 20:21:58 +0000] [6] [INFO] Starting gunicorn 19.9.0
[container] | [2019-01-28 20:21:58 +0000] [6] [ERROR] Retrying in 1 second.
[container] | [2019-01-28 20:21:59 +0000] [6] [ERROR] Retrying in 1 second.
[container] | [2019-01-28 20:22:00 +0000] [6] [ERROR] Retrying in 1 second.
[container] | [2019-01-28 20:22:01 +0000] [6] [ERROR] Retrying in 1 second.
[container] | [2019-01-28 20:22:02 +0000] [6] [ERROR] Retrying in 1 second.
[container] | [2019-01-28 20:22:03 +0000] [6] [ERROR] Can't connect to ('0.0.0.0', 80)
使用与主机相同的UID可以解决我在使用卷时遇到的权限问题。但是由于无法在Dockerfile中使用sudo,所以我不确定如何在不使用root离开容器的情况下使服务器运行。