python
Python Overview
Secure your stack with a hardened Python image freshly-built by Minimus. Minimus images always include the most up-to-date package version for all packages and dependencies contained in the image.
Try It Out
If you don't have a Python project to test out, you can use the following sample Python script that prints random facts about the Python programming language.
In your project directory, save the code below to a new file and name it python-script.py:
import random
# List of statements
statements = [
"Python is The Beginner Friendly Language.",
"Python Does Not Need a Compiler.",
"Python Has One of the Largest Community Support.",
"Python Is a Portable Language."
]
# Randomly shuffle the list and pick the first item
random.shuffle(statements)
# Print the first statement from the shuffled list
print(statements[0])Run the script with the Minimus Python image:
docker run -it --rm \
--name minimus-python-test \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
reg.mini.dev/python \
python python-script.pyYou should get a random fact about Python printed every time you run the script.
Ready to build an app using Dockerfile?
In the next example, 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.
Create a project directory and save the code below to a new docker-compose.yml file:
services:
flask-app:
build: ./app
ports:
- "5000:5000"Create a subdirectory and name it app. Add the following to it:
- Download the sample script
main.pyfile (link). - Save a
requirements.txtfile to list the Python packages that the project depends on. Python’s default package installerpipuses it. For our simple example, save onlyflask>=3.1.1in the file.
In the same directory, save the code below to a new Dockerfile:
# === Build Stage ===
FROM reg.mini.dev/python:latest-dev as builder
WORKDIR /app
RUN python -m venv venv
ENV PATH="/app/venv/bin":$PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# === Runtime Stage ===
FROM reg.mini.dev/python:latest
WORKDIR /app
COPY main.py main.py
COPY --from=builder /app/venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
ENTRYPOINT ["python", "main.py"]Your project directory should now look like this:
your-project-root/
├── docker-compose.yml
└── app/
├── Dockerfile
├── main.py
└── requirements.txtNext, build the app:
docker compose buildDocker Compose will build the app from the app folder. Once built you will see a confirmation ✔ flask-app Built.
Run the app:
docker compose upSend a request to the app:
curl http://127.0.0.1:5000You should get a response with the current date and time.
Once ready to clean up, run the following command to remove the container:
docker compose downTechnical Considerations
The Python image provided by Minimus is a slim, security-hardened alternative to the public image from Docker Hub. The images are largely interchangeable, with a few differences as noted below.
Python built by Minimus:
- Runs as non-root by default for a security-first approach that protects against privilege escalation attacks. The public image runs as root.
- No ports are exposed by default.
- Drill down on the version specification tab to see the default user, listening ports, entrypoint, volumes, environment variables, etc.
The Payoff
A hardened, minimal image that will remain more secure for the long run and accrue vulnerabilities at a slower rate.
- See the risk reduction dashboard for a detailed CVE comparison over the past 30 days.
- Review the compliance report to see the default hardening and security configurations for the image.
Terms & Info
Trademark
This catalog is published by Minimus. All product names, logos, and marks, other than those belonging to Minimus, shown are owned by their respective rights holders and appear here only to identify the open source software each image contains. Minimus claims no ownership of those marks and implies no affiliation with, endorsement by, certification by, or sponsorship by any rights holder.
Disclaimer
Images are provided "as-is" without warranty of any kind. "Hardened" refers to the security configuration applied at the time of build and does not constitute a guarantee of ongoing security or absence of vulnerabilities. The free tier is provided without support, SLA, or guaranteed patching timelines. Security updates may be applied to paid subscriptions before or instead of free tier images. By pulling or using any image you agree to our Terms of Use.