@@ -3,21 +3,21 @@ slug: develop-flask-web-apps-docker-containers-macos
33meta: Learn how to set up and develop a new Flask web application within a Docker container.
44category: post
55date: 2018-03-09
6- modified: 2018-03-09
6+ modified: 2018-03-14
77newsletter: False
88headerimage: /img/180309-flask-docker/header.jpg
99headeralt: Flask, Docker and Apple logos, copyright their respective owners.
1010
1111
1212Adding [ Docker] ( /docker.html ) to your [ Python] ( /why-use-python.html ) and
13- [ Flask] ( /flask.html ) [ development environment's ] ( /development-environments.html )
14- workflow can be a bit confusing when you are just getting started with
15- containers. Let's quickly get Docker installed and configured for developing
16- Flask web applications on your local system.
13+ [ Flask] ( /flask.html ) [ development environment] ( /development-environments.html )
14+ can be confusing when you are just getting started with containers. Let's
15+ quickly get Docker installed and configured for developing Flask web
16+ applications on your local system.
1717
1818
1919## Our Tools
20- This tutorial is written for [ Python 3] ( /python-2-or-3.html ) . It may work with
20+ This tutorial is written for [ Python 3] ( /python-2-or-3.html ) . It will work with
2121Python 2 but I have not tested it with the
2222[ soon-to-be deprecated 2.7 version] ( https://pythonclock.org/ ) .
2323
@@ -116,12 +116,29 @@ docker build -t flaskdock .
116116The above ` docker build ` file uses the ` -t ` flag to tag the image with
117117the name of ` flaskdock ` .
118118
119+ If the build worked successfully we can see the image in with the
120+ ` docker image ls ` command. Give that a try now:
121+
122+ ```
123+ docker image ls
124+ ```
125+
126+ We should then see our tag name in the images list:
127+
128+ ```
129+ REPOSITORY TAG IMAGE ID CREATED SIZE
130+ flaskdock latest 24045e0464af 2 minutes ago 165MB
131+ ```
132+
133+ Our image is ready to load up as a container so we can write a quick
134+ Flask app that we will use to test our environment by running it within
135+ the container.
136+
119137
120138## Coding A Simple Flask app
121139Time to put together a super simple "Hello, World!" Flask web app to test
122140running Python code within our Docker container. Within the current
123- project directory, create a file named ` app.py ` with the following
124- contents:
141+ project directory, create a file named ` app.py ` with the following contents:
125142
126143``` python
127144from flask import Flask, Response
@@ -139,9 +156,10 @@ if __name__ == "__main__":
139156 app.run(" 0.0.0.0" , port = 80 , debug = True )
140157```
141158
142- The above 7 lines of code (not counting blank PEP8-compliant lines) allow our
143- application to return a simple message when run with the Flask development
144- server.
159+ The above 7 lines of code (not counting blank PEP8-compliant lines) in
160+ [ app.py] ( https://github.com/fullstackpython/blog-code-examples/blob/master/docker-flask-mac/app.py )
161+ allow our application to return a simple message when run with the
162+ Flask development server.
145163
146164Save the file and we can give the code a try.
147165
@@ -165,10 +183,19 @@ directory where your project files, especially `app.py`, are located.
165183<img src="/img/180309-flask-docker/flask-app-response.png" width="100%"
166184 class="shot rnd" alt="Flask app responding to requests from within a Docker container.">
167185
186+ Everything worked when you see a simple text-based HTTP response like what
187+ is shown above in the screenshot of my Chrome browser.
188+
189+
168190## What's Next?
169191We just installed Docker and configured a Flask application to run inside a
170192container. That is just the beginning of how you can integrate Docker into
171- your workflow. Next up take a look at the [ Docker] ( /docker.html ) and
193+ your workflow. I strongly recommend reading the
194+ [ Django with PostgreSQL quickstart] ( https://docs.docker.com/compose/django/ )
195+ that will introduce you to Docker Swarm as well as the core Docker container
196+ service.
197+
198+ Next up take a look at the [ Docker] ( /docker.html ) and
172199[ deployment] ( /deployment.html ) pages for more related tutorials.
173200
174201Questions? Let me know via a GitHub
0 commit comments