google cloud run - how to deploy your app as container image
To deploy our app as container image, first we need the app and a dockerfile. A sample git repo for this can be found here (https://github.com/kepungnzai/gcp-cloud-run-python-fastapi).
And this is what the Dockerfile looks like:-
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.13.5-slim
# Allow statements and log messages to immediately appear in the Cloud Run logs
ENV PYTHONUNBUFFERED 1
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# Copying this separately prevents re-running pip install on every code change.
COPY requirements.txt ./
# Install dependencies.
RUN pip install -r requirements.txt
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
CMD exec uvicorn main:app --host 0.0.0.0 --port $PORT
To get things going faster, you can deploy this from the command line using the followings:
gcloud builds submit --tag gcr.io/secondary-471605/my-fastapi-service
gcloud run deploy my-fastapi-service --image gcr.io/secondary-471605/my-fastapi-service
And you should see your app up and running.
Comments