
Creating a test stage
We will get started by creating a Dockerfile at the root of the todobackend repository, meaning your repository structure should look something like this:
todobackend> tree -L 2
.
├── Dockerfile
├── README.md
└── src
├── coverage.xml
├── db.sqlite3
├── manage.py
├── requirements.txt
├── requirements_test.txt
├── todo
├── todobackend
└── unittests.xml
3 directories, 8 files
Let's now define a couple of directives in the newly created Dockerfile:
# Test stage
FROM alpine AS test
LABEL application=todobackend
The FROM directive is the first directive you define in a Dockerfile, and note that we are using the Alpine Linux distribution as the base image. Alpine Linux is a minimalistic distribution that has a much smaller footprint than the more traditional Linux distributions, such as Ubuntu and CentOS, and has become very popular in the container world since Docker adopted Alpine as the distribution of choice for official Docker images.
One keyword you may not have come across is the AS keyword, which is appended to the FROM directive, which configures the Dockerfile as a multi-stage build and names the current stage as test. When you have a multi-stage build, you can include multiple FROM directives, with each stage defined as including the current FROM directive and subsequent directives, up until the next FROM directive.
Next, we use the LABEL directive to attach a label called application with a value of todobackend, which is useful for being able to identify Docker images that support the todobackend application.