a year ago
Hey there! I am trying to deploy my flask app from a Github Repo. I provide a Dockerfile where I specify the eventlet worker (I need this because I am using SocketIO):
FROM python:3.10-slim
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
ENV FLASK_ENV=production
Command to run the app using Gunicorn with eventlet workers
CMD ["gunicorn", "-b", "0.0.0.0:5000", "-k", "eventlet", "-w", "1", "--timeout", "60", "--reload", "app:app"]
In the build progress the Dockerfile is recognized ("Using Detected Dockerfile") but when the server actually starts up it says: [2024-05-02 17:28:57 +0000] [7] [INFO] Using worker: sync, which doesn't work with SocketIO. Deploying the Repo on Render.com works just fine.
Did anyone make similar experiences and knows how to fix that?
3 Replies
a year ago
Two issues with your approach -
Remove the
-b 0.0.0.0:5000
as you are binding to the wrong port, Gunicorn will automatically bind to the correct port without that bind flag.Remove the
--relaod
flag, that should only ever be used during local development, in production that uses extra unnecessary resources and causes instabilities at best.
a year ago
Hey brody, thank you for your answer! I tried it, below you see the complete dockerfile:
Use an official Python runtime as a parent image
FROM python:3.10-slim
Set the working directory in the container
WORKDIR /app
Copy the current directory contents into the container at /app
COPY . /app
Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
Make port 5000 available to the world outside this container
EXPOSE 5000
Define environment variable to handle Flask and SocketIO
ENV FLASK_ENV=production
Command to run the app using Gunicorn with eventlet workers
CMD ["gunicorn", "-k", "eventlet", "-w", "1", "--timeout", "180", "app:app","--log-level","debug"]
Unfortunately Gunicorn still started up with sync workers. I would love to use railway, would be cool to have that fixed.
a year ago
For clarity this is not a platform issue, this is a config issue.
It's likely you have a start command set elsewhere that is overwriting the CMD command in your Dockerfile, check for other start commands in a Procfile, railway.json, or your service settings.