Minimal base images

Definition

Minimal base images are streamlined versions of container images that include only the essential components required to run an application. By reducing the number of packages and libraries, these images minimize the attack surface, decrease the potential for vulnerabilities, and improve performance. They are particularly beneficial in environments where security and efficiency are critical, such as in production deployments.

Secure Settings Example

# Use a minimal base image like Alpine
FROM alpine:3.18

# Install only necessary packages
RUN apk add --no-cache python3 py3-pip

# Copy application code
COPY app.py /app/

# Set the entrypoint
ENTRYPOINT ["python3", "/app/app.py"]

Insecure Settings Example

# Use a larger, more vulnerable base image
FROM ubuntu:latest

# Install unnecessary packages
RUN apt-get update && apt-get install -y python3 python3-pip curl wget

# Copy application code
COPY app.py /app/

# Set the entrypoint
ENTRYPOINT ["python3", "/app/app.py"]