Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask Docker generator should not use flask run #3863

Open
poundifdef opened this issue Aug 16, 2024 · 1 comment
Open

Flask Docker generator should not use flask run #3863

poundifdef opened this issue Aug 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@poundifdef
Copy link

The generated Dockerfile for flask should have a different CMD.

Right now it runs python3 -m flask run. This is incorrect. Flask warns about this in their docs:

Do not use the development server when deploying to production. It is intended for use only during local development. It is not designed to be particularly secure, stable, or efficient.

When you look at the fly logs, it also emits a warning:

This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

I’d propose the following changes:

diff --git a/Dockerfile b/Dockerfile
index 7f8924f..ce75327 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,9 +10,10 @@ WORKDIR /code
 
 COPY requirements.txt requirements.txt
 RUN pip3 install -r requirements.txt
+RUN pip3 install gunicorn
 
 COPY . .
 
 EXPOSE 8080
 
-CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=8080"]
+CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]

This will do the following:

  • Installs requirements.txt
  • If gunicorn was installed already from the requirements file, pip3 install gunicorn is a noop. Otherwise it will install the latest version.
  • Updates the default Dockerfile to use gunicorn, rather than the flask debug server

Alternatively, you could look for gunicorn in requirements.txt and add if it’s missing.

@poundifdef poundifdef added the bug Something isn't working label Aug 16, 2024
@poundifdef poundifdef changed the title Flask Docker generator should not use python3 -m flask run Flask Docker generator should not use flask run Aug 16, 2024
@Jaspie88
Copy link

Is there any issue using Poetry with Gunicorn? Negates the need for a requirements.txt and manages python packages for us.

Also the default docker part 2 build uses python-slim which is missing several core python features that Flask-SQAlchemy needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants