{"id":"9a76ba5e-6ab3-4112-8a7a-df0f3e5c1075","title":"Dockerizing .NET 10 Web APIs for Google Cloud Run: A 2026 Deployment Guide","content":"# Dockerizing .NET 10 Web APIs for Google Cloud Run: A 2026 Deployment Guide\n\nMeta 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.\n\n---\n\n## Introduction\n\nDocker 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.\n\nIn this **2026 deployment guide**, we’ll cover:\n- Setting up a .NET 10 Web API for Docker\n- Optimizing Dockerfiles for performance and security\n- Deploying to Google Cloud Run with best practices\n- Monitoring and scaling your API effortlessly\n\nLet’s dive in!\n\n---\n\n## Why Dockerize .NET 10 Web APIs for Google Cloud Run?\n\nBefore we jump into the technical steps, let’s explore why this combination is a game-changer in 2026.\n\n### **1. Scalability and Cost Efficiency**\nGoogle 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.\n\n### **2. Simplified Deployment**\nDockerizing 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.\n\n### **3. Performance Optimizations in .NET 10**\n.NET 10 introduces:\n- **Smaller container images** (reduced by ~30% compared to .NET 8)\n- **Faster cold starts** (critical for serverless environments like Cloud Run)\n- **Improved AOT (Ahead-of-Time) compilation** for reduced memory usage\n\n### **4. Seamless Integration with Google Cloud**\nGoogle 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**.\n\n---\n\n## Step 1: Setting Up Your .NET 10 Web API for Docker\n\n## Prerequisites\nBefore you start, ensure you have the following installed:\n- [.NET 10 SDK](https://dotnet.microsoft.com/download)\n- [Docker Desktop](https://www.docker.com/products/docker-desktop/)\n- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install)\n- A Google Cloud Platform (GCP) account\n\n---\n\n### **1. Create a .NET 10 Web API**\nRun the following commands to create a new .NET 10 Web API project:\n\n```bash\ndotnet new webapi -n DotNet10CloudRunApi\ncd DotNet10CloudRunApi\n```\n\n### **2. Test Your API Locally**\nStart the API to ensure it works:\n\n```bash\ndotnet run\n```\n\nOpen your browser and navigate to `https://localhost:5001/weatherforecast`. You should see a JSON response.\n\n---\n\n### **3. Add a Dockerfile**\nCreate a file named `Dockerfile` in the root of your project. Use the following optimized configuration for .NET 10:\n\n```dockerfile\n# Use the .NET 10 SDK to build the application\nFROM mcr.microsoft.com/dotnet/sdk:10.0 AS build\nWORKDIR /src\nCOPY . .\nRUN dotnet restore \"DotNet10CloudRunApi.csproj\"\nRUN dotnet publish \"DotNet10CloudRunApi.csproj\" -c Release -o /app/publish\n\n# Use the .NET 10 runtime for the final image\nFROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime\nWORKDIR /app\nCOPY --from=build /app/publish .\nENTRYPOINT [\"dotnet\", \"DotNet10CloudRunApi.dll\"]\n```\n\n#### **Key Optimizations in This Dockerfile:**\n- **Multi-stage build**: Reduces the final image size by separating the build and runtime environments.\n- **Official .NET 10 images**: Ensures compatibility and security updates.\n- **AOT compilation**: (Optional) Add `<PublishAot>true</PublishAot>` to your `.csproj` file for further optimizations.\n\n---\n\n### **4. Build and Test Your Docker Image**\nRun the following commands to build and test your Docker image locally:\n\n```bash\ndocker build -t dotnet10-cloudrun-api .\ndocker run -p 8080:80 dotnet10-cloudrun-api\n```\n\nNavigate to `http://localhost:8080/weatherforecast` to verify the API is running inside Docker.\n\n---\n\n## Step 2: Deploying to Google Cloud Run\n\nNow that your .NET 10 Web API is dockerized, let’s deploy it to **Google Cloud Run**.\n\n---\n\n### **1. Set Up Google Cloud Project**\n1. Go to the [Google Cloud Console](https://console.cloud.google.com/).\n2. Create a new project or select an existing one.\n3. Enable the following APIs:\n   - **Cloud Run API**\n   - **Artifact Registry API** (for storing Docker images)\n   - **Cloud Build API** (for automated deployments)\n\n---\n\n### **2. Push Your Docker Image to Artifact Registry**\nGoogle Cloud Run requires your Docker image to be stored in **Artifact Registry** or **Google Container Registry**.\n\n#### **Create an Artifact Registry Repository**\n```bash\ngcloud artifacts repositories create dotnet10-repo \\\n  --repository-format=docker \\\n  --location=us-central1 \\\n  --description=\"Repository for .NET 10 Docker images\"\n```\n\n#### **Tag and Push Your Docker Image**\n```bash\n# Tag your local image\ndocker tag dotnet10-cloudrun-api us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api\n\n# Authenticate Docker with Google Cloud\ngcloud auth configure-docker us-central1-docker.pkg.dev\n\n# Push the image to Artifact Registry\ndocker push us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api\n```\n\nReplace `YOUR-PROJECT-ID` with your Google Cloud project ID.\n\n---\n\n### **3. Deploy to Google Cloud Run**\nRun the following command to deploy your API:\n\n```bash\ngcloud run deploy dotnet10-cloudrun-api \\\n  --image us-central1-docker.pkg.dev/YOUR-PROJECT-ID/dotnet10-repo/dotnet10-cloudrun-api \\\n  --platform managed \\\n  --region us-central1 \\\n  --allow-unauthenticated \\\n  --port 80\n```\n\n#### **Flags Explained:**\n- `--image`: Specifies the Docker image to deploy.\n- `--platform managed`: Deploys to Google Cloud Run (fully managed).\n- `--region`: Choose a region close to your users (e.g., `us-central1`, `europe-west1`).\n- `--allow-unauthenticated`: Makes the API publicly accessible. Remove this flag for private APIs.\n- `--port`: Specifies the port your API listens on (default is 80 for .NET).\n\n---\n\n### **4. Verify Your Deployment**\nAfter deployment, Google Cloud Run will provide a URL for your API. For example:\n```\nhttps://dotnet10-cloudrun-api-xyz.a.run.app\n```\n\nTest the API by navigating to:\n```\nhttps://dotnet10-cloudrun-api-xyz.a.run.app/weatherforecast\n```\n\n---\n\n## Step 3: Optimizing and Securing Your Deployment\n\nDeploying your API is just the beginning. Let’s optimize and secure it for production.\n\n---\n\n### **1. Enable Auto-Scaling**\nGoogle Cloud Run automatically scales your API based on traffic. However, you can configure the following settings:\n- **Minimum instances**: Keep a minimum number of instances warm to reduce cold starts.\n- **Maximum instances**: Limit the number of instances to control costs.\n\n#### **Update Auto-Scaling Settings**\n```bash\ngcloud run services update dotnet10-cloudrun-api \\\n  --min-instances 1 \\\n  --max-instances 10 \\\n  --region us-central1\n```\n\n---\n\n### **2. Secure Your API**\n#### **Restrict Access**\nRemove the `--allow-unauthenticated` flag if your API should be private. Use **Identity-Aware Proxy (IAP)** or **API keys** for authentication.\n\n#### **Enable HTTPS**\nGoogle Cloud Run automatically provisions an HTTPS certificate for your API. Ensure all traffic is redirected to HTTPS by default.\n\n#### **Use Environment Variables for Secrets**\nAvoid hardcoding secrets in your Docker image. Use **Google Cloud Secret Manager** or environment variables:\n\n```bash\ngcloud run services update dotnet10-cloudrun-api \\\n  --update-env-vars \"DB_CONNECTION_STRING=your_connection_string\" \\\n  --region us-central1\n```\n\n---\n\n### **3. Monitor Performance**\nGoogle Cloud Run integrates with **Cloud Monitoring** and **Cloud Logging**. Set up alerts for:\n- High latency\n- Error rates\n- Traffic spikes\n\n#### **View Logs**\n```bash\ngcloud logging read \"resource.type=cloud_run_revision\" --limit 50\n```\n\n---\n\n### **4. Optimize Cold Starts**\nCold starts can impact user experience. Here’s how to minimize them:\n\n#### **Use Minimum Instances**\nKeep at least one instance warm to handle sudden traffic spikes.\n\n```bash\ngcloud run services update dotnet10-cloudrun-api \\\n  --min-instances 1 \\\n  --region us-central1\n```\n\n#### **Optimize Your Docker Image**\n- Use **AOT compilation** in .NET 10 for faster startup.\n- Reduce the image size by removing unnecessary dependencies.\n- Use **distroless** or **Alpine-based** images for the runtime stage.\n\n#### **Example Optimized Dockerfile**\n```dockerfile\n# Build stage\nFROM mcr.microsoft.com/dotnet/sdk:10.0 AS build\nWORKDIR /src\nCOPY . .\nRUN dotnet restore \"DotNet10CloudRunApi.csproj\"\nRUN dotnet publish \"DotNet10CloudRunApi.csproj\" -c Release -o /app/publish /p:PublishAot=true\n\n# Runtime stage with Alpine\nFROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime\nWORKDIR /app\nCOPY --from=build /app/publish .\nENTRYPOINT [\"dotnet\", \"DotNet10CloudRunApi.dll\"]\n```\n\n---\n\n## Best Practices for .NET 10 on Google Cloud Run\n\nHere are some **pro tips** to get the most out of your deployment:\n\n### **1. Use Health Checks**\nEnsure your API is healthy by configuring a **liveness probe**:\n\n```bash\ngcloud run services update dotnet10-cloudrun-api \\\n  --health-check-path /healthz \\\n  --region us-central1\n```\n\nAdd a health check endpoint to your API:\n\n```csharp\napp.MapGet(\"/healthz\", () => \"Healthy\");\n```\n\n---\n\n### **2. Implement CI/CD**\nAutomate your deployments using **Google Cloud Build**. Create a `cloudbuild.yaml` file:\n\n```yaml\nsteps:\n  # Build the Docker image\n  - name: \"gcr.io/cloud-builders/docker\"\n    args: [\"build\", \"-t\", \"us-central1-docker.pkg.dev/$PROJECT_ID/dotnet10-repo/dotnet10-cloudrun-api\", \".\"]\n\n  # Push the Docker image\n  - name: \"gcr.io/cloud-builders/docker\"\n    args: [\"push\", \"us-central1-docker.pkg.dev/$PROJECT_ID/dotnet10-repo/dotnet10-cloudrun-api\"]\n\n  # Deploy to Cloud Run\n  - name: \"gcr.io/google.com/cloudsdktool/cloud-sdk\"\n    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\"]\n```\n\nTrigger builds on code changes by connecting your repository to **Cloud Build**.\n\n---\n\n### **3. Use Custom Domains**\nMap a custom domain to your Cloud Run service for a professional touch:\n\n1. Go to the **Cloud Run** section in the Google Cloud Console.\n2. Select your service and click **Triggers**.\n3. Click **Add Custom Domain** and follow the instructions.\n\n---\n\n### **4. Optimize Costs**\n- **Set maximum instances** to avoid runaway scaling.\n- **Use CPU throttling** for non-CPU-intensive APIs.\n- **Monitor usage** with Cloud Billing reports.\n\n---\n\n## Conclusion\n\nDockerizing 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:\n\n1. Setting up a .NET 10 Web API for Docker.\n2. Optimizing Dockerfiles for performance and security.\n3. Deploying to Google Cloud Run with best practices.\n4. Monitoring, scaling, and securing your API.\n\nBy following these steps, you’re well on your way to leveraging the full potential of **.NET 10** and **Google Cloud Run** in 2026.\n\n---\n\n## Call to Action\n\nReady to take your deployment to the next level?\n\n\uD83D\uDE80 **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!\n\n\uD83D\uDCCC **Bookmark this guide** for future reference, and don’t forget to explore [Google Cloud’s documentation](https://cloud.google.com/run/docs) for more advanced configurations.\n\nHappy coding! \uD83D\uDCBB✨","excerpt":"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....","slug":"dockerizing-net-10-web-apis-for-google-cloud-run-a-2026-deployment-guide","authorId":"1","author":{"id":"1","username":"ajith","email":"contact@ajithjoseph.com","name":"Ajith Joseph","bio":"AI Lead Engineer in Bengaluru with 13+ years in software. Builds production AI agent systems and writes about Copilot Studio, MCP, .NET and React.","avatarUrl":"images/users/ajith.jpg","createdAt":"2025-03-02T00:00:00"},"createdAt":"2026-05-21T18:15:56.987","updatedAt":"2026-05-21T18:15:56.987","likesCount":0,"commentsCount":0,"featured":true,"tags":[{"id":6,"name":"api"},{"id":22,"name":"run"},{"id":39,"name":"your"},{"id":43,"name":"cloud"},{"id":67,"name":"google"}],"readingTimeMinutes":8,"difficultyLevel":"intermediate"}