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:

from flask import Flask
app = Flask(__name__) 1


@app.route('/') 
def hello_world():
    

Get Using Docker now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.