Docs: update sample application initiation in venv (#15506)

* Docs: update sample application initiation in venv

Until now, readers would install 'Flask' on their main system
python environment, freeze their entire packages, and grep only
the 'Flask' package! So they would be missing all the other
dependencies in their requirements file.

With this commit, a better practice is followed. First, create a
clean virtual environment, then install 'Flask' and freeze
everything into the requirements file.

Also, I recommend using 'python3 -m pip freeze' instead of 'pip3
freeze' while in the virtual environment. This is because
sometimes hidden quirks of 'pip' will ignore the actiavted
environment and freeze the entire python packages in the
system (e.g. in ArchLinux).

* Docs: update python sample testing application

In the previous commit, I forgot to update the 'Test the
application' section so that the users activate the virtual
environment first.

This commit fixes that.

Co-authored-by: Stefan Scherer <stefan.scherer@docker.com>
This commit is contained in:
Pedram Ashofteh-Ardakani 2022-10-22 01:17:24 +03:30 committed by GitHub
parent f01d1bc739
commit 678d56c1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -28,9 +28,11 @@ Lets create a simple Python application using the Flask framework that wel
```console
$ cd /path/to/python-docker
$ pip3 install Flask
$ pip3 freeze | grep Flask >> requirements.txt
$ touch app.py
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python3 -m pip install Flask
(.venv) $ python3 -m pip freeze > requirements.txt
(.venv) $ touch app.py
```
Now, lets add some code to handle simple web requests. Open this working directory in your favorite IDE and enter the following code into the `app.py` file.
@ -49,7 +51,9 @@ def hello_world():
Lets start our application and make sure its running properly. Open your terminal and navigate to the working directory you created.
```console
$ python3 -m flask run
$ cd /path/to/python-docker
$ source .venv/bin/activate
(.venv) $ python3 -m flask run
```
To test that the application is working properly, open a new browser and navigate to `http://localhost:5000`.