A FastAPI image
Notes// archive From the original Code Walker docs. Kept for reference, so some versions and commands may be out of date.
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:
podman pull registry.access.redhat.com/ubi9/python-312:latestExamine the Containerfile
Containerfiledockerfile
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.pyBuild a container image:
podman build -t localhost/fastapi-serve-static:1.0.0 .Run container:
podman run -d -p 8080:8080 --name fastapi-serve-static localhost/fastapi-serve-static:1.0.0Check it is running:
podman psCONTAINER 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