Gunicorn 自行运行但不在 docker 容器中
Gunicorn runs by itself but not in docker container
我正在尝试 运行 Gunicorn 在 docker 容器中这是我的 docker 文件
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-c", "/app/etc/gunicorn.py", "backend:app"]
我试过将 backend:app
与 app:app
app:backend
等交换
但没有任何效果它总是出错并输出
Failed to find application object 'app' in 'app'
构建后我 运行:
docker run -it -p 8000:8000 backend:latest bash
这是我从中复制到 /app
的文件夹结构。
│ main.py
│ requirements.txt
│
├───backend
│ │ __init__.py
│ │
│ ├───cards
│ │ cards_views.py
│ │ __init__.py
│ │
│
└───etc
gunicorn.py
nginx.conf
如果我运行:
gunicorn -c /backend-flask/etc/gunicorn.py backend:app
在容器外 运行 非常完美。所以它一定与我的文件夹结构有关,但我无法弄清楚。
添加:
pip install -r /app/requirements.txt
Dockerimage 文件解决了这个问题,并使用:
docker run -it --entrypoint=sh [my container]
最终的 dockerfile 如下所示:
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
RUN pip install -r /app/requirements.txt
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-c", "/app/etc/gunicorn.py", "backend:app"]
我正在尝试 运行 Gunicorn 在 docker 容器中这是我的 docker 文件
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-c", "/app/etc/gunicorn.py", "backend:app"]
我试过将 backend:app
与 app:app
app:backend
等交换
但没有任何效果它总是出错并输出
Failed to find application object 'app' in 'app'
构建后我 运行:
docker run -it -p 8000:8000 backend:latest bash
这是我从中复制到 /app
的文件夹结构。
│ main.py
│ requirements.txt
│
├───backend
│ │ __init__.py
│ │
│ ├───cards
│ │ cards_views.py
│ │ __init__.py
│ │
│
└───etc
gunicorn.py
nginx.conf
如果我运行:
gunicorn -c /backend-flask/etc/gunicorn.py backend:app
在容器外 运行 非常完美。所以它一定与我的文件夹结构有关,但我无法弄清楚。
添加:
pip install -r /app/requirements.txt
Dockerimage 文件解决了这个问题,并使用:
docker run -it --entrypoint=sh [my container]
最终的 dockerfile 如下所示:
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
RUN pip install -r /app/requirements.txt
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-c", "/app/etc/gunicorn.py", "backend:app"]