Dockerizing .NET 10 Web APIs for Google Cloud Run: A 2026 Deployment Guide

Meta Description: Learn how to dockerize .NET 10 Web APIs and deploy them to Google Cloud Run in 2026 with this step-by-step guide. Optimize, secure, and scale effortlessly....

By Ajith joseph · Thu May 21 2026 · Updated Thu May 21 2026 · 8 min read · intermediate

#api #run #your #cloud #google

Meta Description: Learn how to dockerize .NET 10 Web APIs and deploy them to Google Cloud Run in 2026 with this step-by-step guide. Optimize, secure, and scale effortlessly.


Introduction

Docker and Google Cloud Run have revolutionized how developers deploy and scale applications. With the release of .NET 10, Microsoft has introduced performance improvements, reduced container sizes, and enhanced cloud-native capabilities. If you're looking to dockerize .NET 10 Web APIs and deploy them to Google Cloud Run, this guide is for you.

In this 2026 deployment guide, we’ll cover:

  • Setting up a .NET 10 Web API for Docker
  • Optimizing Dockerfiles for performance and security
  • Deploying to Google Cloud Run with best practices
  • Monitoring and scaling your API effortlessly

Let’s dive in!


Why Dockerize .NET 10 Web APIs for Google Cloud Run?

Before we jump into the technical steps, let’s explore why this combination is a game-changer in 2026.

1. Scalability and Cost Efficiency

Google Cloud Run is a serverless platform that automatically scales your API based on demand. You only pay for the resources you use, making it cost-effective for startups and enterprises alike.

2. Simplified Deployment

Dockerizing your .NET 10 Web API ensures consistency across environments. Whether you're developing locally or deploying to the cloud, Docker eliminates the "it works on my machine" problem.

3. Performance Optimizations in .NET 10

.NET 10 introduces:

  • Smaller container images (reduced by ~30% compared to .NET 8)
  • Faster cold starts (critical for serverless environments like Cloud Run)
  • Improved AOT (Ahead-of-Time) compilation for reduced memory usage

4. Seamless Integration with Google Cloud

Google Cloud Run natively supports Docker containers, making it easy to deploy, monitor, and manage your API with tools like Cloud Build, Artifact Registry, and Cloud Monitoring.


Step 1: Setting Up Your .NET 10 Web API for Docker

Prerequisites

Before you start, ensure you have the following installed:

  • .NET 10 SDK
  • Docker Desktop
  • Google Cloud SDK
  • A Google Cloud Platform (GCP) account

1. Create a .NET 10 Web API

Run the following commands to create a new .NET 10 Web API project:

dotnet new webapi -n DotNet10CloudRunApi
cd DotNet10CloudRunApi

2. Test Your API Locally

Start the API to ensure it works:

dotnet run

Open your browser and navigate to https://localhost:5001/weatherforecast. You should see a JSON response.


3. Add a Dockerfile

Create a file named Dockerfile in the root of your project. Use the following optimized configuration for .NET 10:

# Use the .NET 10 SDK to build the application
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "DotNet10CloudRunApi.csproj"
RUN dotnet publish "DotNet10CloudRunApi.csproj" -c Release -o /app/publish

# Use the .NET 10 runtime for the final image
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "DotNet10CloudRunApi.dll"]

Key Optimizations in This Dockerfile:

  • Multi-stage build: Reduces the final image size by separating the build and runtime environments.
  • Official .NET 10 images: Ensures compatibility and security updates.
  • AOT compilation: (Optional) Add <PublishAot>true</PublishAot> to your .csproj file for further optimizations.

4. Build and Test Your Docker Image

Run the following commands to build and test your Docker image locally:

docker build -t dotnet10-cloudrun-api .
docker run -p 8080:80 dotnet10-cloudrun-api

Navigate to http://localhost:8080/weatherforecast to verify the API is running inside Docker.


Step 2: Deploying to Google Cloud Run

Now that your .NET 10 Web API is dockerized, let’s deploy it to Google Cloud Run.


1. Set Up Google Cloud Project

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Enable the following APIs:
    • Cloud Run API
    • Artifact Registry API (for storing Docker images)
    • Cloud Build API (for automated deployments)

2. Push Your Docker Image to Artifact Registry

Google Cloud Run requires your Docker image to be stored in Artifact Registry or Google Container Registry.

Create an Artifact Registry Repository

gcloud artifacts repositories create dotnet10-repo \
  --repository-format=docker \
  --location=us-central1 \
  --description="Repository for .NET 10 Docker images"

Tag and Push Your Docker Image

# Tag your local image
docker tag dotnet10-cloudrun-api us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api

# Authenticate Docker with Google Cloud
gcloud auth configure-docker us-central1-docker.pkg.dev

# Push the image to Artifact Registry
docker push us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api

Replace YOUR-PROJECT-ID with your Google Cloud project ID.


3. Deploy to Google Cloud Run

Run the following command to deploy your API:

gcloud run deploy dotnet10-cloudrun-api \
  --image us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --port 80

Flags Explained:

  • --image: Specifies the Docker image to deploy.
  • --platform managed: Deploys to Google Cloud Run (fully managed).
  • --region: Choose a region close to your users (e.g., us-central1, europe-west1).
  • --allow-unauthenticated: Makes the API publicly accessible. Remove this flag for private APIs.
  • --port: Specifies the port your API listens on (default is 80 for .NET).

4. Verify Your Deployment

After deployment, Google Cloud Run will provide a URL for your API. For example:

https://dotnet10-cloudrun-api-xyz.a.run.app

Test the API by navigating to:

https://dotnet10-cloudrun-api-xyz.a.run.app/weatherforecast

Step 3: Optimizing and Securing Your Deployment

Deploying your API is just the beginning. Let’s optimize and secure it for production.


1. Enable Auto-Scaling

Google Cloud Run automatically scales your API based on traffic. However, you can configure the following settings:

  • Minimum instances: Keep a minimum number of instances warm to reduce cold starts.
  • Maximum instances: Limit the number of instances to control costs.

Update Auto-Scaling Settings

gcloud run services update dotnet10-cloudrun-api \
  --min-instances 1 \
  --max-instances 10 \
  --region us-central1

2. Secure Your API

Restrict Access

Remove the --allow-unauthenticated flag if your API should be private. Use Identity-Aware Proxy (IAP) or API keys for authentication.

Enable HTTPS

Google Cloud Run automatically provisions an HTTPS certificate for your API. Ensure all traffic is redirected to HTTPS by default.

Use Environment Variables for Secrets

Avoid hardcoding secrets in your Docker image. Use Google Cloud Secret Manager or environment variables:

gcloud run services update dotnet10-cloudrun-api \
  --update-env-vars "DB_CONNECTION_STRING=your_connection_string" \
  --region us-central1

3. Monitor Performance

Google Cloud Run integrates with Cloud Monitoring and Cloud Logging. Set up alerts for:

  • High latency
  • Error rates
  • Traffic spikes

View Logs

gcloud logging read "resource.type=cloud_run_revision" --limit 50

4. Optimize Cold Starts

Cold starts can impact user experience. Here’s how to minimize them:

Use Minimum Instances

Keep at least one instance warm to handle sudden traffic spikes.

gcloud run services update dotnet10-cloudrun-api \
  --min-instances 1 \
  --region us-central1

Optimize Your Docker Image

  • Use AOT compilation in .NET 10 for faster startup.
  • Reduce the image size by removing unnecessary dependencies.
  • Use distroless or Alpine-based images for the runtime stage.

Example Optimized Dockerfile

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "DotNet10CloudRunApi.csproj"
RUN dotnet publish "DotNet10CloudRunApi.csproj" -c Release -o /app/publish /p:PublishAot=true

# Runtime stage with Alpine
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "DotNet10CloudRunApi.dll"]

Best Practices for .NET 10 on Google Cloud Run

Here are some pro tips to get the most out of your deployment:

1. Use Health Checks

Ensure your API is healthy by configuring a liveness probe:

gcloud run services update dotnet10-cloudrun-api \
  --health-check-path /healthz \
  --region us-central1

Add a health check endpoint to your API:

app.MapGet("/healthz", () => "Healthy");

2. Implement CI/CD

Automate your deployments using Google Cloud Build. Create a cloudbuild.yaml file:

steps:
  # Build the Docker image
  - name: "gcr.io/cloud-builders/docker"
    args: ["build", "-t", "us-central1-docker.pkg.dev/$PROJECT_ID/dotnet10-repo/dotnet10-cloudrun-api", "."]

  # Push the Docker image
  - name: "gcr.io/cloud-builders/docker"
    args: ["push", "us-central1-docker.pkg.dev/$PROJECT_ID/dotnet10-repo/dotnet10-cloudrun-api"]

  # Deploy to Cloud Run
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    args: ["gcloud", "run", "deploy", "dotnet10-cloudrun-api", "--image", "us-central1-docker.pkg.dev/$PROJECT_ID/dotnet10-repo/dotnet10-cloudrun-api", "--platform", "managed", "--region", "us-central1"]

Trigger builds on code changes by connecting your repository to Cloud Build.


3. Use Custom Domains

Map a custom domain to your Cloud Run service for a professional touch:

  1. Go to the Cloud Run section in the Google Cloud Console.
  2. Select your service and click Triggers.
  3. Click Add Custom Domain and follow the instructions.

4. Optimize Costs

  • Set maximum instances to avoid runaway scaling.
  • Use CPU throttling for non-CPU-intensive APIs.
  • Monitor usage with Cloud Billing reports.

Conclusion

Dockerizing your .NET 10 Web API and deploying it to Google Cloud Run is a powerful combination for building scalable, cost-effective, and high-performance applications. In this guide, we covered:

  1. Setting up a .NET 10 Web API for Docker.
  2. Optimizing Dockerfiles for performance and security.
  3. Deploying to Google Cloud Run with best practices.
  4. Monitoring, scaling, and securing your API.

By following these steps, you’re well on your way to leveraging the full potential of .NET 10 and Google Cloud Run in 2026.


Call to Action

Ready to take your deployment to the next level?

🚀 Start by dockerizing your .NET 10 Web API today and deploy it to Google Cloud Run. Share your experience in the comments or reach out for help!

📌 Bookmark this guide for future reference, and don’t forget to explore Google Cloud’s documentation for more advanced configurations.

Happy coding! 💻✨

  1. AJ's Tech Notes
  2. Dockerizing .NET 10 Web APIs for Google Cloud Run: A 2026 Deployment Guide