Skip to main content
Google Cloud Run is a managed platform for deploying and scaling serverless applications. Google handles the infrastructure for you. This guide deploys a Bun HTTP server to Google Cloud Run using a Dockerfile.
Before continuing, make sure you have:

1

Initialize gcloud by select/creating a project

Make sure that you’ve initialized the Google Cloud CLI. gcloud init logs you in and prompts you to either select an existing project or create a new one.For more help with the Google Cloud CLI, see the official documentation.
terminal
2

(Optional) Store your project info in environment variables

Set variables for your project ID and number so they’re easier to reuse in the following steps.
terminal
3

Link a billing account

List your available billing accounts and link one to your project:
terminal
Link your billing account to your project. Replace [BILLING_ACCOUNT_ID] with the ID of your billing account.
terminal
4

Enable APIs and configure IAM roles

Activate the necessary services and grant Cloud Build permissions:
terminal
These commands enable Cloud Run (run.googleapis.com) and Cloud Build (cloudbuild.googleapis.com), which are required for deploying from source. Cloud Run runs your containerized app, while Cloud Build builds and packages it.The IAM binding grants the Compute Engine service account ($PROJECT_NUMBER-compute@developer.gserviceaccount.com) permission to build and deploy images on your behalf.
5

Add a Dockerfile

Create a new Dockerfile in the root of your project. This file contains the instructions to initialize the container, copy your local project files into it, install dependencies, and start the application.
Dockerfile
Make sure that the start command corresponds to your application’s entry point. This can also be CMD ["bun", "run", "start"] if you have a start script in your package.json.If your app doesn’t have dependencies, you can omit the RUN bun install --production --frozen-lockfile line.
Create a new .dockerignore file in the root of your project. It lists the files and directories to exclude from the container image, such as node_modules, which keeps builds faster and smaller:
.dockerignore
6

Deploy your service

Make sure you’re in the directory containing your Dockerfile, then deploy directly from your local source:
Update the --region flag to your preferred region, or omit it to select a region interactively.
terminal
7

Visit your live application

Your Bun application is now live.Visit the Service URL (https://my-bun-app-....us-west1.run.app) to confirm everything works as expected.