Skip to main content
In this tutorial, we will build a custom Python app using Docker Compose and a multi-stage Dockerfile. The build stage uses latest-dev because it requires the package installer pip. The runtime stage uses the fully distroless image to achieve the most secure app.
1

Create Docker Compose file

Create a project directory and save the code below to a new docker-compose.yml file:
2

Create a Python project

Create a subdirectory and name it app. Add the following to it:
  • Save the following sample script as a new main.py file.
  • Save a requirements.txt file to list the Python packages that the project depends on. Python’s default package installer pip uses it. For our simple example, save only:
3

Create the Dockerfile

In the same directory, save the code below to a new Dockerfile:
Note that the builder stage uses reg.mini.dev/python:latest-dev so it can utilize PIP. The runtime stage uses the fully distroless production image - reg.mini.dev/python:latest.
4

Review the project directory

Your project directory should now look like this:
5

Build the app

You are now ready to build the app using Docker Compose:
Docker Compose will build the app from the app folder. Once built, you will see a confirmation:
6

Run and test the app

Run the app:
Test the app by sending it a request:
You should get a response with the current date and time.
7

Clean up

Once ready to clean up, run the following command to remove the container:
Last modified on June 9, 2026