Chapter 5. Using Docker in Development
Throughout Part II, we are going to develop a simple web application that returns a unique image for a given string, similar to the identicons used on GitHub and Stack Overflow for users with no set image. We will write the application using the Python programming and the Flask web framework. Python was chosen for this example because it is commonly used and succinct and readable. Don’t worry if you don’t program in Python. We will focus on how to interact with Docker, not on details of the Python code.1 Similarly, Flask was chosen because it is lightweight and easy to understand. We will be using Docker to manage all our dependencies, so there is no need install Python or Flask on your host computer.
This chapter will focus on setting up a container-based workflow and getting tools in place before we begin development in the next chapter.
Say “Hello World!”
Let’s begin by creating a web server that just returns “Hello World!” First, create a new directory called identidock to hold our project. Inside this directory, create a subdirectory app that will hold our Python code. Inside the app directory, create a file called identidock.py:
$ tree identidock/
identidock/
└── app
└── identidock.py
1 directory, 1 file
Put the following code in identidock.py:
fromflaskimportFlaskapp=Flask(__name__)@app.route('/')defhello_world():
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access