5.2 Containerize an application

State/Version: 20250408

5.2 Build the application image 📦️

The sourcecode for my demo application is located on github/gerundium

Step by step guide:

  1. Create your Containerfile

    # Containerfile.yaml
    # Use the official Python image from the Docker Hub
    FROM python:3.12-slim
    
    # Set labels
    LABEL maintainer="gerundium@mailbox.org"
    LABEL app="gerundium-brand-voting-app"
    
    # Set the working directory inside the container
    WORKDIR /app
    
    # Copy the requirements.txt file into the container at /app
    COPY requirements.txt /app/
    
    # Install the Python dependencies
    RUN pip install --no-cache-dir -r requirements.txt
    
    # Copy the rest of the application files into the container
    COPY . /app/
    
    # Expose the port that Streamlit will run on
    EXPOSE 8501
    
    # Command to run the application when the container starts
    CMD ["streamlit", "run", "gerundium-brand-voting-app.py"]
    
  2. Trigger the image build process

    COMMIT_SHA=$(git rev-parse --short HEAD); docker build -t gerundium/github-event-poller:$COMMIT_SHA -t gerundium/github-event-poller:latest  --file ./Containerfile .
    
Explanation💡
COMIMIT_SHA Create a unique commit SHA
-t gerundium/github-event-poller:$COMMIT_SHA Set image tag 1
-t gerundium/github-event-poller:latest Set image tag 2
--file ./Containerfile . Specify the souce file for the build command
  1. Push image and tags to your registry

    docker push gerundium/github-event-poller:$COMMIT_SHA
    docker push gerundium/brand-voting-app:latest