I am trying to run Gunicorn inside a docker container here is my docker file
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
EXPOSE 8000
ENTRYPOINT ["gunicorn", "-c", "/app/etc/gunicorn.py", "backend:app"]
I've tried interchanging backend:app
with app:app
app:backend
etc but nothing works it always errors out and outputs
Failed to find application object 'app' in 'app'
After I build it I run:
docker run -it -p 8000:8000 backend:latest bash
Here is the folder structure from which I copy to /app
to.
│ main.py
│ requirements.txt
│
├───backend
│ │ __init__.py
│ │
│ ├───cards
│ │ cards_views.py
│ │ __init__.py
│ │
│
└───etc
gunicorn.py
nginx.conf
If I run:
gunicorn -c /backend-flask/etc/gunicorn.py backend:app
Outside of the container it runs perfectly. So it must be something with my folder structure but I cant figure it out.
Adding:
pip install -r /app/requirements.txt
to the Dockerimage file fixed the issue, that and using:
docker run -it --entrypoint=sh [my container]
the final dockerfile looks like:
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"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.