FastAPI Example
The following example steps through the process of building a container image and running the application using Podman.
A good simple example is the single file FastAPI application which serve static web pages:
Single file FastAPI application
We'll be using the following image:
Examine the Containerfile
Containerfile
FROM registry.access.redhat.com/ubi9/python-312:latest
LABEL maintainer="Richard Walker"
ENV PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8
WORKDIR /opt/app-root/src
COPY . /opt/app-root/src
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
USER root
RUN chown -R 1001:1001 /opt/app-root/src
RUN chmod -R 775 /opt/app-root/src
EXPOSE 8080
USER 1001
CMD python main.py
Build a container image:
Run container:
Check it is running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad23d40a9dfd localhost/fastapi-serve-static:1.0.0 /bin/sh -c python... 3 seconds ago Up 4 seconds 0.0.0.0:8080->8080/tcp, 8080/tcp fastapi-serve-static
The application should now be accessible at http://localhost:8080