1

我试图不在我的 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 离开容器的情况下让服务器运行。

4

0 回答 0