Flask Docker generator should not use `flask run`

Open
#3,863 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
50/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
docker, flask, python
Domain
backend, devops

Research direction

Start with scanner/templates/flask/Dockerfile and compare its current command with Flask’s deployment guidance linked in the issue. Check how the generated image is expected to expose and start the application, then update the template to use a production WSGI server instead of flask run. Done means generated Flask deployments no longer emit the development-server warning.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
Go
Stars
1.7k
Forks
311
Avg merge
12h 50m
Merged PRs (30d)
78

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from superfly/flyctl

All issues in superfly/flyctl

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.