Testing with Docker
While doing development or QA, it will be helpful if we can check our code against different environments. For example, we may need to check our Python code between different versions of Python, or on different Linux distributions such as Fedora, Ubuntu, CentOS, and so on. For this recipe, we will use Flask, which is a microframework for Python (https://www.palletsprojects.com/p/flask/). We will use the sample code from Flask's GitHub repository. I chose this to keep things simple, and it is easier to use for other recipes as well.
For this recipe, we will create images with one container with Python 2.7 and another with Python 3.7. We'll then use sample Python test code to run against each container.
Getting ready
Make the following preparations:
- As we are going to use example code from Flask's GitHub repository, let's clone it:
$ cd /tmp $ git clone https://github.com/pallets/flask
- Create a
Dockerfile_2.7
file, as follows, and then build an image from it:
...