-
Notifications
You must be signed in to change notification settings - Fork 8k
Add Python get started docs #12184
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
Add Python get started docs #12184
Conversation
|
Deploy preview for docsdocker ready! Built with commit acf969c |
language/python/develop.md
Outdated
|
|
||
| In the above command, we used the same MySQL image to connect to the database but this time, we passed the ‘mysql’ command to the container with the `-h` flag containing the name of our MySQL container name. Press CTRL-D to exit the MySQL interactive terminal. | ||
|
|
||
| Okay, now that we have a running MySQL, let’s update `app.py` to use MySQL as a datastore. Let’s also add some routes to our server. One for fetching records and one for inserting records. |
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.
Should we add here a link to the app setup in the Build images page as a reminder? Just in case we land directly on this page or forgot our application setup 😅
I would find useful also to have the directory structure/tree for the python app as we have to edit the files next:
python-docker
|____ app.py
|____ requirements.txt
|____ Dockerfile
| ``` | ||
|
|
||
| In the above command, we used the same MySQL image to connect to the database but this time, we passed the ‘mysql’ command to the container with the `-h` flag containing the name of our MySQL container name. Press CTRL-D to exit the MySQL interactive terminal. | ||
|
|
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.
I would add a new section title here to make it clear we change focus. We discuss next how to connect our python application to the database running in a container.
language/python/develop.md
Outdated
|
|
||
| In this module, we’ll walk through setting up a local development environment for the application we built in the previous modules. We’ll use Docker to build our images and Docker Compose to make everything a whole lot easier. | ||
|
|
||
| ## Local database and containers |
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.
Should we change section title to Running a database in a container/ containerized database or something else to quickly describe what we talk about in this part? And maybe we can move the first paragraph in the intro part.
language/python/develop.md
Outdated
| First, let’s add the `mysql-connector-python `module to our application using pip. | ||
| ```shell | ||
| $ pip install mysql-connector-python |
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.
Maybe it would be easier to manually add the dependency to requirements.txt. Same as in https://github.com/docker/awesome-compose/blob/master/nginx-flask-mysql/backend/requirements.txt
From what I understand pip freeze command dumps all installed local packages, not only the ones we need for the app. I may be wrong, I have never used pip freeze before 😅
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.
Flask==1.1.1
mysql-connector==2.2.9
| Now, let’s run our container. | ||
| ```shell | ||
| $ docker run \ |
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.
Maybe outline here that we add the container to the DB network. This way we can access the DB by its container name. We can also add a comment in the python code where we connect to the DB.
Signed-off-by: Usha Mandya <usha.mandya@docker.com>
72b4246 to
c0cc76f
Compare
Signed-off-by: Usha Mandya <usha.mandya@docker.com>
|
@aiordache Addressed the review comments we discussed earlier:
PTAL. |
language/python/build-images.md
Outdated
|
|
||
| ```shell | ||
| $ cd /path/to/python-docker | ||
| $ pip install Flask |
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.
I suggest to consistently use pip3 instead of pip. We suggest to install Python 3.8 or later and I'm not sure about if the magic "pip3 = pip" on all Mac and Windows platforms. Maybe @aiordache can confirm?
language/python/build-images.md
Outdated
| Let’s start our application and make sure it’s running properly. Open your terminal and navigate to the working directory you created. | ||
|
|
||
| ```shell | ||
| $ python -m flask run |
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.
Same suggestion to use python3 instead of python.
On my Mac I have eg. two version of Pythons installed, don't know when and why I have them, more because it was needed to run some tools. I'm not a Python developer, so I'm always confused 😅
Signed-off-by: Usha Mandya <usha.mandya@docker.com>
|
Thanks @StefanScherer. That's right. We do have pip3 within some of the examples. I've updated pip to pip3 to be consistent. |
Signed-off-by: Usha Mandya <usha.mandya@docker.com>
|
|
||
| Switch back to the terminal where our server is running and you should see the following requests in the server logs. The data and timestamp will be different on your machine. | ||
|
|
||
| ```shel |
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: small typo
StefanScherer
left a comment
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 🐍
Signed-off-by: Usha Mandya usha.mandya@docker.com
Adding getting started docs for Python