-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Update Python and Flask usage in Compose tutorial #8609
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
Conversation
* Uses the modern Python 3.7 image, as 3.4 is EOL. * Separates copying and installing requirements from copying project, to make rebuilds more efficient. * Uses the recommended `flask run` command. This is especially needed on Windows, where `app.py` incorrectly looks like an executable file when copying into Docker. * Uses the `FLASK_ENV` env var to control development mode.
This is not needed when using the recommended `flask run` command to run the development server.
Deploy preview for docsdocker ready! Built with commit 86f7166 |
Deploy preview for docsdocker ready! Built with commit f5da7af |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @davidism!
Just a couple of minor changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit but otherwise LGTM
* Install the Python dependencies. | ||
* Set the default command for the container to `python app.py`. | ||
* Set environment variables used by the `flask` command. | ||
* Install gcc so Python packages such as MarkupSafe and SQLAlchemy can compile speedups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Since this is just a Compose get started guide, I'm not sure we need to include Python optimisations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is one of two official Docker documents introducing devs to using Flask with Docker, I'd rather they get a reasonable experience without having to discover it later, especially since it's non-obvious that speedups are not compiled. Overall I think the focus is still on Compose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you agree, or would you like me to change something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that we're conflating getting started with Compose and optimising a Python app. That might overload new users with too much information.
I did LGTM the PR though as it's net better than what we have currently.
@usha-mandya is there anything else we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't think of anything else, @chris-crone. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
COPY
instead ofADD
, since behavior ofADD
is not used, as recommended in theDockerfile
reference.flask run
command. This is especially needed on Windows, whereapp.py
incorrectly looks like an executable file when copying into Docker. 0.15.0 causes OSError: [Errno 8] Exec format error: in Docker for Windows pallets/werkzeug#1482FLASK_ENV
env var to control development mode (debugger, reloader). This is only set when demonstrating thevolumes
option for live updating files, as it should not be used in production. Note that the development server (flask run
,app.run()
) should not be used in production either, but I think that's outside the scope of this change.