How runtime rebasing works on Cloud Run
The endless cycle of monitoring container images for security vulnerabilities, rebuilding, and redeploying is a chore I try to skip. When you enable automatic base image updates, Cloud Run patches operating system (OS) packages and language runtimes (such as Node.js or Python) underneath your running service automatically. You don't have to trigger a build or redeploy your service to pick up a security fix.
Cloud Run applies these updates using runtime rebasing, replacing an outdated Google-managed base image with a patched version without downtime or a new deployment. (To set this up on a service right away, see Automating OS patches on Cloud Run.) The diagram below compares an initial deployment with a runtime rebase:

I'll walk through how container layers make rebasing possible, how buildpacks package your application, how Cloud Run swaps the base image at startup, and what rebasing doesn't cover.
Container layers need a rebaseable seam
To see why rebasing works, start with how container images organize files on disk. Internally, a container image consists of immutable layers that the container runtime merges (overlays) into a single unified root filesystem when starting a container instance.
The first layer is the base image, which contains the OS packages (such as Ubuntu system libraries, OpenSSL, and root certificates) and, for languages such as Node.js, Python, or Java, the language runtime. Your application code and its third-party dependencies sit in the application layers on top of that base image.
Rebasing replaces the base image without rebuilding
In a traditional Docker workflow, patching a vulnerability in the base image requires
rebuilding (docker build) the entire container image. The build downloads
the updated base image and re-runs your build steps to recreate the application layers
on top of it, producing a new container image that you then have to deploy.
Rebasing takes a different approach. Instead of running a new build, it takes a rebaseable container image and rebases your unchanged application layers onto a newly patched base image. Because your build steps don't re-run, your application code and installed dependencies stay identical while the OS and language runtime underneath get patched.
Overwriting base image files breaks the seam
For rebasing to work reliably, there needs to be a strict separation (a rebaseable seam) between the base image and your application layers. Specifically, your application layers can't contain files that overwrite or conflict with files in the base image. As long as your layers stay self-contained in their own directories, swapping the base image underneath won't break file paths or package metadata.
Maintaining that seam in a standard Dockerfile takes discipline because
every RUN instruction can modify arbitrary paths across the filesystem. As
soon as a Dockerfile runs
apt-get update && apt-get install, that layer writes shared
libraries into the /usr/lib/ directory and updates the package database in
/var/lib/dpkg/, coupling your application layer to that exact base image
snapshot and breaking the seam. If you want to construct a rebaseable image by hand with
a multi-stage Dockerfile, read
Building rebaseable container images with Docker from scratch.
Building rebaseable images with buildpacks
Instead of writing a Dockerfile by hand, you can build container images
that preserve a rebaseable seam automatically using
Cloud Native Buildpacks (CNB). Whether you run a local build with the
pack CLI
or deploy from source to Cloud Run, an open-source builder image runs a set of
language buildpacks across three main phases:
-
Detect: The builder analyzes your source files to select matching buildpacks,
such as choosing the Node.js buildpacks when it finds a
package.jsonfile. -
Build: The selected buildpacks download dependencies, compile assets if
needed, and write the output into isolated layer directories instead of system paths
such as
/usr/lib/. - Export: The builder packages the application layers produced during the build into an exported container image.
Refer to the full lifecycle documentation for details on the additional analysis and caching steps that speed up subsequent builds.
When you deploy from source to Cloud Run by running gcloud run deploy in a
directory without a Dockerfile (or when deploying a Cloud Run function),
Cloud Build runs
Google Cloud's buildpacks. When base image updates are enabled, the exporter takes the separation between layers
one step further: it uses the language runtime during the Build phase to
install your dependencies, and then exports only your application layers onto
an empty scratch image, leaving out both the OS and the language runtime so
Cloud Run can supply them at startup.
Deploying from source with base image updates
To see how Google Cloud's buildpacks assemble a rebaseable image in practice, you'll
create a minimal Express web service, deploy it from source to Cloud Run with base image
updates enabled, and inspect the resulting Cloud Build log. Before starting, make sure
you have the gcloud CLI installed and a Google Cloud project with billing
enabled.
Create a new directory for the sample Express service and switch into it:
mkdir example-app && cd example-app
Add a package.json file that declares Express as a dependency:
{
"name": "example-app",
"main": "index.js",
"dependencies": {
"express": "^5.2.1"
}
}
Next, add an index.js file that starts an HTTP server on port
8080 (or the port set in the PORT environment variable) and
returns the active Node.js runtime version:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send(`Running on Node.js ${process.version}\n`);
});
const port = process.env.PORT || 8080;
app.listen(port, () => console.log(`Listening on port ${port}`));
Set your Google Cloud project ID in your shell:
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
Enable the Cloud Run Admin API, the Cloud Build API, and the Artifact Registry API so your project's default build service account is provisioned before you deploy:
gcloud services enable \
run.googleapis.com \
cloudbuild.googleapis.com \
artifactregistry.googleapis.com \
--project "$GOOGLE_CLOUD_PROJECT"
Operation "operations/acf.p2-123456789012-8cf8578d-0664-4963-904b-86613dd4eb25" finished successfully.
With the APIs enabled, deploy the service example-app from your
example-app directory. If prompted to create the
cloud-run-source-deploy Artifact Registry repository, press
Y to continue:
gcloud run deploy example-app \
--source . \
--base-image nodejs24 \
--automatic-updates \
--region europe-west1 \
--allow-unauthenticated \
--project "$GOOGLE_CLOUD_PROJECT"
Building using Buildpacks and deploying container to Cloud Run service [example-app] in project
[YOUR_PROJECT_ID] region [europe-west1]
✓ Building and deploying new service... Done.
✓ Validating configuration...
✓ Creating Container Repository...
✓ Uploading sources...
✓ Building Container...
✓ Setting IAM Policy...
✓ Creating Revision...
✓ Routing traffic...
Done.
Service [example-app] revision [example-app-00001-97t] has been deployed and is serving 100 percent of traffic.
Service URL: https://example-app-123456789012.europe-west1.run.app
The following flags configure the build and deployment:
-
--source .uploads your current directory to Cloud Build and packages it into a rebaseable image with Google Cloud's buildpacks. -
--base-image nodejs24tells Cloud Run to rebase your application layers onto the Node.js 24 base image. -
--automatic-updatesenables base image updates for this source deployment. -
--region europe-west1deploys the service to the Belgium region. -
--allow-unauthenticatedmakes the test endpoint publicly reachable without credentials.
Once the deployment finishes, fetch the service URL and send a request with
curl to confirm that the service responds with the Node.js version from the
base image:
SERVICE_URL=$(gcloud run services describe example-app \
--region europe-west1 \
--project "$GOOGLE_CLOUD_PROJECT" \
--format="value(status.url)")
curl "$SERVICE_URL"
Running on Node.js v24.22.1
Inspecting the buildpack phases in the build log
Every source deployment records its Cloud Build ID on the Cloud Run service under the
run.googleapis.com/build-id annotation. Extract that build ID and stream
the build log to see how the builder packaged your application layers:
BUILD_ID=$(gcloud run services describe example-app \
--region europe-west1 \
--project "$GOOGLE_CLOUD_PROJECT" \
--format="value(metadata.annotations['run.googleapis.com/build-id'])")
gcloud builds log "$BUILD_ID" \
--region europe-west1 \
--project "$GOOGLE_CLOUD_PROJECT"
...
=== Running detector ===
target distro name/version labels not found, reading /etc/os-release file
3 of 7 buildpacks participating
google.nodejs.runtime 1.0.0
google.nodejs.npm 1.1.1
google.utils.label-image 0.0.2
=== Running builder ===
...
=== Node.js - Runtime Using Runner (google.nodejs.runtime@1.0.0) ===
Using runtime version from GOOGLE_RUNTIME_VERSION: 24.22.1
Using exact version 24.22.1 for Node.js
***** CACHE MISS: "nodejs"
Installing Node.js v24.22.1.
...
=== Node.js - Npm Using Runner (google.nodejs.npm@1.1.1) ===
...
Installing application dependencies.
--------------------------------------------------------------------------------
Running "npm ci --quiet --no-fund --no-audit (NODE_ENV=production)"
added 65 packages in 1s
Done "npm ci --quiet --no-fund --no-audit (NODE_ENV=production)" (1.214411198s)
=== Utils - Label Image Using Runner (google.utils.label-image@0.0.2) ===
...
Adding image label google.base-image: europe-west1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/nodejs24
Adding image label google.run-image:
europe-west1-docker.pkg.dev/serverless-runtimes/google-24/scratch/nodejs24:nodejs24_20261104_24_22_1_RC00
=== Running exporter ===
Warning: No cached data will be used, no cache specified.
Adding layer 'google.nodejs.runtime:heapsize'
Adding layer 'google.nodejs.npm:env'
Adding layer 'buildpacksio/lifecycle:launch.sbom'
Added 1/1 app layer(s)
...
Saving europe-west1-docker.pkg.dev/YOUR_PROJECT_ID/cloud-run-source-deploy/example-app:latest...
In the build log, you can trace all three CNB phases:
-
detectorselects thegoogle.nodejs.runtime,google.nodejs.npm, andgoogle.utils.label-imagebuildpacks. -
builderdownloads Node.jsv24.22.1inside the build container sonpm cican install your Express dependency, and thengoogle.utils.label-imagerecords two image labels:google.base-image(pointing to thenodejs24base image) andgoogle.run-image(pointing to an emptyscratch/nodejs24image). -
exporterskips exporting the Node.js runtime (google.nodejs.runtime:node) and writes only thegoogle.nodejs.runtime:heapsizescript, thegoogle.nodejs.npm:envmetadata, and your/workspaceapplication layer (Added 1/1 app layer(s)) onto thatscratchimage.
Because the exported image omits both Ubuntu and Node.js, the image saved to Artifact Registry is roughly 2 MB and contains only your application layers above the rebaseable seam.
Rebasing application layers at container startup
When you deploy a rebaseable image with base image updates enabled, Cloud Run stores
your application layers separately from the OS and language runtime. Instead of pulling
a monolithic image that bundles the runtime, Cloud Run records the target base image
(such as nodejs24) in the service configuration. Whenever Cloud Run starts
a new container instance, it fetches the latest version of that base image and
dynamically overlays your stored application layers onto it to assemble the instance's
root filesystem.
Because Cloud Run rebases your application layers onto the base image at instance startup, every new container instance starts with the latest patched base image. When Google publishes a security patch for a base image while your service is running, Cloud Run performs a zero-downtime rolling restart: it starts new container instances with the patched base image, routes traffic to them once they pass startup probes, and shuts down the older instances without creating a new revision or requiring a deployment from you.
Inspecting runtime rebasing in the service YAML
Seeing what changes in the Cloud Run service resource definition
(service.yaml) when you enable base image updates makes the separation
between your application layers and the base image concrete. Export the YAML
configuration of the deployed example-app service using
gcloud run services describe:
gcloud run services describe example-app \
--project "$GOOGLE_CLOUD_PROJECT" \
--region europe-west1 \
--format export
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: example-app
...
spec:
template:
metadata:
annotations:
run.googleapis.com/base-images:
'{"":"europe-west1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/nodejs24"}'
spec:
containers:
- image:
europe-west1-docker.pkg.dev/YOUR_PROJECT_ID/cloud-run-source-deploy/example-app@sha256:c576b906edb652cc...
...
runtimeClassName: run.googleapis.com/linux-base-image-update
Two interdependent fields inside the spec.template block control runtime
rebasing (if either field is missing, Cloud Run discards the other and disables base
image updates):
-
The
spec.template.spec.runtimeClassNamefield is set torun.googleapis.com/linux-base-image-update, which instructs Cloud Run to rebase the container at startup. -
The
run.googleapis.com/base-imagesannotation inspec.template.metadata.annotationsmaps each container to the regional Artifact Registry URI of its base image.
Notice that the run.googleapis.com/base-images annotation is formatted as a
JSON map with an empty string ("") as the key for the default container.
This map structure supports
multi-container deployments (sidecars), where each container in the revision can specify its own base image by container
name.
What runtime rebasing doesn't cover
While runtime rebasing automates OS and language runtime patching, three architectural boundaries determine what it can and can't update.
Custom OS packages require a Dockerfile
Because Cloud Run replaces the base image underneath your application layers, you can't
install extra OS-level packages with apt-get install or bring a custom base
image. Installing system packages writes files into the /usr and
/var/lib/dpkg directories that conflict with the base image seam. If your
service depends on system binaries or shared C libraries that aren't included in the
base images, you need to build and patch a full Dockerfile-based container
image yourself.
Statically compiled binaries only get OS patches
How much runtime rebasing covers depends on how your language compiles and links code.
For compiled languages such as Go or Rust, the compiler typically links the language
runtime and standard library directly into a static binary at build time, so picking up
a language-level fix still requires rebuilding your binary. For those workloads, runtime
rebasing only patches OS-level components in the base image, such as root certificates,
timezone data (tzdata), and the libc library when dynamically
linked. Languages such as Node.js, Python, Java, Ruby, PHP, and .NET get broader
coverage because the language runtime itself lives inside the base image and updates in
place.
Application dependencies remain your responsibility
Base image updates only replace the base image and never modify your application layers.
Your third-party packages (node_modules packages, Python wheels, or Go
modules) stay frozen at the exact versions packaged when you deployed the revision. If a
security vulnerability is disclosed in a library inside your application dependencies,
such as express in package.json, you still need to update your
dependency manifest, run your build, and deploy a new Cloud Run revision.