
上QQ阅读APP看书,第一时间看更新
Installing system dependencies
To get started creating the release stage, we can add a new FROM directive at the bottom of the Dockerfile, which Docker will treat as the start of a new stage:
# Test stage
FROM alpine AS test
LABEL application=todobackend
...
...
...
...
# Test entrypoint
CMD ["python3", "manage.py", "test", "--noinput", "--settings=todobackend.settings_test"]
# Release stage
FROM alpine
LABEL application=todobackend
# Install operating system dependencies
RUN apk add --no-cache python3 mariadb-client bash
In the preceding example, you can see the release image is based, once again, on the Alpine Linux image, which is an excellent choice for a release image given its very small footprint. You can see that we install fewer operating-system dependencies, which includes the following:
- python3: The Python 3 interpreter and runtime is required given the sample application is a Python application
- mariadb-client: Includes system libraries required to communicate with the MySQL application database
- bash: Useful for troubleshooting and executing entry point scripts, which we will discuss in later chapters.
Note that instead of installing the python3-dev and mariadb-dev packages, we only need to install the non development versions of these packages, given we compiled and built all application dependences as precompiled wheels in the test stage.