{"id":53819,"date":"2025-09-15T10:12:07","date_gmt":"2025-09-15T00:12:07","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53819"},"modified":"2025-09-15T10:12:11","modified_gmt":"2025-09-15T00:12:11","slug":"build-lean-reliable-net-docker-images-for-production","status":"publish","type":"post","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","title":{"rendered":"Build Lean Reliable .NET Docker Images for Production"},"content":{"rendered":"\n<p>In this blog post How to Build Lean Reliable .NET Docker Images for Production we will walk through how to package .NET apps into small, fast, and secure Docker images that run the same way on your laptop and in production.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>We\u2019ll start with a high-level view of how <a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/category\/docker\/\">containers<\/a> and .NET fit together, then move into a practical, battle-tested Dockerfile you can adapt today. Along the way we\u2019ll cover base image choices, multi-stage builds, caching, security hardening, multi-arch images, and CI\/CD tips.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-containers-and-net-play-well-together\">Why containers and .NET play well together<\/h2>\n\n\n\n<p>Docker packages your application and its dependencies into an immutable image. At runtime, that image becomes a container with isolated processes, limited filesystem views, and predictable configuration. The image is built as a stack of layers; when you change only part of your app, Docker reuses unchanged layers for speed.<\/p>\n\n\n\n<p>.NET complements this model nicely. Microsoft ships official SDK and runtime images with consistent tags, security updates, and support for multiple architectures. With multi-stage builds, you can compile in a larger SDK image and run in a smaller runtime image. That gives you fast, repeatable builds and compact production containers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-moving-parts-in-a-net-container\">The moving parts in a .NET container<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Base image: The starting point. For .NET you\u2019ll usually pick SDK (build time) and ASP.NET or runtime (run time) images from Microsoft\u2019s registry.<\/li>\n\n\n\n<li>Layers: Each command in your Dockerfile adds a layer. Arrange commands to maximize caching and minimize rebuilds.<\/li>\n\n\n\n<li>Registry: Where images live (e.g., Docker Hub, ACR, ECR, GCR). CI\/CD pushes images there; orchestrators pull them.<\/li>\n\n\n\n<li>Entrypoint: The command that starts your app inside the container (e.g., dotnet MyApp.dll).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-choose-the-right-base-images-for-net\">Choose the right base images for .NET<\/h2>\n\n\n\n<p>Microsoft publishes well-maintained .NET images on mcr.microsoft.com. Common choices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>mcr.microsoft.com\/dotnet\/sdk:8.0 \u2013 full SDK for restore, build, and publish.<\/li>\n\n\n\n<li>mcr.microsoft.com\/dotnet\/aspnet:8.0 \u2013 runtime for ASP.NET Core web apps.<\/li>\n\n\n\n<li>mcr.microsoft.com\/dotnet\/runtime:8.0 or runtime-deps:8.0 \u2013 for console\/services without ASP.NET.<\/li>\n<\/ul>\n\n\n\n<p>OS flavor trade-offs:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Debian\/Ubuntu (default): Great compatibility, good tooling, slightly larger.<\/li>\n\n\n\n<li>Alpine: Very small, uses musl libc; some native dependencies may need tweaks. Validate performance and compatibility.<\/li>\n<\/ul>\n\n\n\n<p>Tip: Pin your base images to a major.minor version (e.g., 8.0) or digest for deterministic builds.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-a-production-grade-dockerfile-for-asp-net-core\">A production-grade Dockerfile for ASP.NET Core<\/h2>\n\n\n\n<p>Here\u2019s a clean, multi-stage Dockerfile for a typical ASP.NET Core app named MyApp. It favors caching, small size, and non-root execution.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-94d7c20bed7b9eeb1d9bdbdf07c1a816\"><code># syntax=docker\/dockerfile:1.7\nARG DOTNET_VERSION=8.0\n\nFROM mcr.microsoft.com\/dotnet\/sdk:${DOTNET_VERSION} AS build\nWORKDIR \/src\n\n# 1) Copy project files first to enable restore caching\nCOPY MyApp\/*.csproj MyApp\/\n# Optional: include a NuGet.Config if you use private feeds\n# COPY NuGet.Config .\/\nRUN dotnet restore MyApp\/MyApp.csproj --disable-parallel\n\n# 2) Copy the rest of the source and build\nCOPY . .\nWORKDIR \/src\/MyApp\nRUN dotnet build MyApp.csproj -c Release -o \/app\/build\nRUN dotnet publish MyApp.csproj -c Release -o \/app\/publish \/p:UseAppHost=false\n\nFROM mcr.microsoft.com\/dotnet\/aspnet:${DOTNET_VERSION} AS runtime\nENV ASPNETCORE_URLS=http:\/\/+:8080\nWORKDIR \/app\n\n# Create and use a non-root user\nRUN useradd -m -u 10001 app &amp;&amp; chown -R app \/app\nUSER app\n\nEXPOSE 8080\nCOPY --from=build \/app\/publish .\nENTRYPOINT &#91;\"dotnet\", \"MyApp.dll\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-this-dockerfile-does\">What this Dockerfile does<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Separates build and runtime: compile in the SDK, run in the slim runtime.<\/li>\n\n\n\n<li>Optimizes caching: dotnet restore happens before copying the full source.<\/li>\n\n\n\n<li>Publishes for Release: strips unneeded build assets and reduces size.<\/li>\n\n\n\n<li>Runs as non-root: a simple, effective security improvement.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-build-and-run-locally\">Build and run locally<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d5be4b5ef54f00fc2aef2a94c1a00662\"><code>docker build -t myapp:1.0 .\ndocker run --rm -p 8080:8080 myapp:1.0<\/code><\/pre>\n\n\n\n<p>Open http:\/\/localhost:8080 to test.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-make-builds-fast-and-repeatable\">Make builds fast and repeatable<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-use-a-dockerignore\">Use a .dockerignore<\/h3>\n\n\n\n<p>Prevent large or irrelevant files from bloating your build context:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-19c98f98b598e80341a05b6f76ae1e5b\"><code># .dockerignore\n**\/bin\n**\/obj\n.git\nnode_modules\n*.user\n*.suo\nDockerfile\ndocker-compose.*<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-lock-dependencies\">Lock dependencies<\/h3>\n\n\n\n<p>For deterministic restores, check in packages.lock.json and use locked mode in CI:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-800e7af7dc04cede40162b2fd56f45b2\"><code>dotnet restore --locked-mode<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-structure-your-dockerfile-for-cache-hits\">Structure your Dockerfile for cache hits<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Copy .csproj first and restore; only when package references change will that step invalidate.<\/li>\n\n\n\n<li>Copy the rest of the source and build\/publish afterwards.<\/li>\n\n\n\n<li>Avoid RUN commands that change frequently near the top of the file.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-keep-images-small-and-secure\">Keep images small and secure<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose the smallest suitable runtime: aspnet for web, runtime\/runtime-deps for services.<\/li>\n\n\n\n<li>Publish with trimming where appropriate: <code>dotnet publish -c Release -p:PublishTrimmed=true<\/code> (test thoroughly as trimming can remove reflection-heavy code).<\/li>\n\n\n\n<li>Run as a non-root user (as shown) and keep file permissions minimal.<\/li>\n\n\n\n<li>Avoid installing shell tools in the runtime image unless you need them.<\/li>\n\n\n\n<li>Scan images for vulnerabilities regularly with your preferred scanner.<\/li>\n\n\n\n<li>Keep base images updated; rebuild when Microsoft ships security patches.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-working-with-secrets-and-configuration\">Working with secrets and configuration<\/h2>\n\n\n\n<p>Never bake secrets into images. Prefer environment variables, mounted files, or a secrets manager. For private NuGet feeds during build, use Docker BuildKit secrets:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-a2f92f3f204afab8cda227670bd67392\"><code># build with BuildKit and a secret\n# DOCKER_BUILDKIT=1 docker build --secret id=nuget_config,src=.\/NuGet.Config -t myapp:1.0 .\n\n# Dockerfile snippet (build stage)\n# RUN --mount=type=secret,id=nuget_config,target=\/root\/.nuget\/NuGet.Config \\\n#     dotnet restore MyApp\/MyApp.csproj<\/code><\/pre>\n\n\n\n<p>At runtime, keep configuration external: pass environment variables (<code>-e Key=Value<\/code>) or mount configuration files (<code>-v \/path:\/app\/config<\/code>), or rely on your orchestrator\u2019s config\/secrets facilities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-multi-architecture-images\">Multi-architecture images<\/h2>\n\n\n\n<p>If you deploy to both x64 and ARM64 (e.g., cloud + Apple Silicon dev machines), publish a multi-arch image:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9d4ed5d4333631132c704c0e6126bf71\"><code>docker buildx create --use --name mybuilder\n# Build and push a manifest for amd64 and arm64\ndocker buildx build \\\n  --platform linux\/amd64,linux\/arm64 \\\n  -t registry.example.com\/myapp:1.0 \\\n  --push .<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-add-tests-to-your-image-build\">Add tests to your image build<\/h2>\n\n\n\n<p>Catch issues early by running tests in a separate stage. Example layout:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-57d256a94da386ccd5cd1ecaa6c53329\"><code>FROM mcr.microsoft.com\/dotnet\/sdk:8.0 AS tests\nWORKDIR \/src\nCOPY . .\nRUN dotnet test --configuration Release --no-build --logger \"trx;LogFileName=test.trx\"<\/code><\/pre>\n\n\n\n<p>Wire this stage before publish so failing tests stop the pipeline.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-optional-advanced-pattern-native-aot-for-ultra-small-services\">Optional advanced pattern Native AOT for ultra-small services<\/h2>\n\n\n\n<p>For certain workloads, .NET 8\u2019s Native AOT can produce a single self-contained binary with very fast startup.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d8febfafe67ab490359a4a3a7977a370\"><code># Dockerfile (simplified)\nFROM mcr.microsoft.com\/dotnet\/sdk:8.0 AS build\nWORKDIR \/src\nCOPY . .\nRUN dotnet publish -c Release -r linux-x64 -p:PublishAot=true -o \/app\/out\n\nFROM debian:bookworm-slim AS runtime\nRUN useradd -m -u 10001 app\nWORKDIR \/app\nCOPY --from=build \/app\/out\/MyApp .\nUSER app\nENTRYPOINT &#91;\".\/MyApp\"]\n<\/code><\/pre>\n\n\n\n<p>Note: AOT has compatibility limits; validate your libraries and reflection usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-quick-checklist\">Quick checklist<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use multi-stage builds (SDK for build, runtime for run).<\/li>\n\n\n\n<li>Pin base image versions; rebuild regularly for patches.<\/li>\n\n\n\n<li>Adopt a solid .dockerignore.<\/li>\n\n\n\n<li>Run as non-root; keep images minimal.<\/li>\n\n\n\n<li>Externalize secrets and config.<\/li>\n\n\n\n<li>Automate with BuildKit, caching, and CI\/CD.<\/li>\n\n\n\n<li>Scan images and monitor CVEs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wrapping-up\">Wrapping up<\/h2>\n\n\n\n<p>Building lean, reliable .NET Docker images is mostly about good structure and consistent habits: pick the right base, use multi-stage builds, keep layers cache-friendly, and ship non-root runtime images. With these practices in place, your images will build faster, deploy safer, and run predictably from developer machines to production.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/\">Mastering Docker environment variables with Docker<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/06\/27\/how-to-restore-an-azure-vm-os-disk-using-azure-powershell\/\">How to Restore an Azure VM OS Disk Using Azure PowerShell<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2024\/09\/05\/block-copy-paste-from-ios-business-apps-with-intune\/\">Block Copy Paste from iOS Business Apps with Intune<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/05\/13\/publish-a-blazor-net-app-with-vs-code-to-azure\/\">Publish a Blazor .NET App With VS Code to Azure<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/11\/the-benefits-of-using-docker-compose-for-teams-and-projects\/\">The Benefits of Using Docker Compose for Teams and Projects<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to build small, secure, and fast .NET Docker images using multi-stage builds, caching, and best practices that work in local dev and production.<\/p>\n","protected":false},"author":1,"featured_media":53821,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Build Lean Reliable .NET Docker Images for Production","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[27,13,70],"tags":[],"class_list":["post-53819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-blog","category-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Build Lean Reliable .NET Docker Images for Production - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build Lean Reliable .NET Docker Images for Production\" \/>\n<meta property=\"og:description\" content=\"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-15T00:12:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-15T00:12:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production-1024x683.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CPI Staff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CPI Staff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Build Lean Reliable .NET Docker Images for Production\",\"datePublished\":\"2025-09-15T00:12:07+00:00\",\"dateModified\":\"2025-09-15T00:12:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/\"},\"wordCount\":896,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/how-to-build-lean-reliable-net-docker-images-for-production.png\",\"articleSection\":[\".NET\",\"Blog\",\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/\",\"url\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/\",\"name\":\"Build Lean Reliable .NET Docker Images for Production - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/how-to-build-lean-reliable-net-docker-images-for-production.png\",\"datePublished\":\"2025-09-15T00:12:07+00:00\",\"dateModified\":\"2025-09-15T00:12:11+00:00\",\"description\":\"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/how-to-build-lean-reliable-net-docker-images-for-production.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/how-to-build-lean-reliable-net-docker-images-for-production.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/15\\\/build-lean-reliable-net-docker-images-for-production\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build Lean Reliable .NET Docker Images for Production\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#website\",\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\",\"name\":\"Cloud Pro Inc - CPI Consulting Pty Ltd\",\"description\":\"Cloud, AI &amp; Cybersecurity Consulting | Melbourne\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\",\"name\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\",\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"width\":500,\"height\":500,\"caption\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\",\"name\":\"CPI Staff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"caption\":\"CPI Staff\"},\"sameAs\":[\"http:\\\/\\\/www.cloudproinc.com.au\"],\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/author\\\/cpiadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Build Lean Reliable .NET Docker Images for Production - CPI Consulting","description":"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","og_locale":"en_US","og_type":"article","og_title":"Build Lean Reliable .NET Docker Images for Production","og_description":"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.","og_url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","og_site_name":"CPI Consulting","article_published_time":"2025-09-15T00:12:07+00:00","article_modified_time":"2025-09-15T00:12:11+00:00","og_image":[{"width":1024,"height":683,"url":"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production-1024x683.png","type":"image\/png"}],"author":"CPI Staff","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CPI Staff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#article","isPartOf":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Build Lean Reliable .NET Docker Images for Production","datePublished":"2025-09-15T00:12:07+00:00","dateModified":"2025-09-15T00:12:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/"},"wordCount":896,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","articleSection":[".NET","Blog","Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","name":"Build Lean Reliable .NET Docker Images for Production - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","datePublished":"2025-09-15T00:12:07+00:00","dateModified":"2025-09-15T00:12:11+00:00","description":"Learn to build lean reliable .NET Docker images for production with our practical guide on Dockerfile best practices.","breadcrumb":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#primaryimage","url":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","contentUrl":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudproinc.azurewebsites.net\/"},{"@type":"ListItem","position":2,"name":"Build Lean Reliable .NET Docker Images for Production"}]},{"@type":"WebSite","@id":"https:\/\/cloudproinc.azurewebsites.net\/#website","url":"https:\/\/cloudproinc.azurewebsites.net\/","name":"Cloud Pro Inc - CPI Consulting Pty Ltd","description":"Cloud, AI &amp; Cybersecurity Consulting | Melbourne","publisher":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudproinc.azurewebsites.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization","name":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd","url":"https:\/\/cloudproinc.azurewebsites.net\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/logo\/image\/","url":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","contentUrl":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","width":500,"height":500,"caption":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd"},"image":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e","name":"CPI Staff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","caption":"CPI Staff"},"sameAs":["http:\/\/www.cloudproinc.com.au"],"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/author\/cpiadmin\/"}]}},"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","jetpack-related-posts":[{"id":53790,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","url_meta":{"origin":53819,"position":0},"title":"Keep .NET App Running in Docker","author":"CPI Staff","date":"September 8, 2025","format":false,"excerpt":"Learn how to containerise a .NET app, start it automatically, and keep it running with Docker and Docker Compose\u2014production-friendly, developer-happy.","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 1x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 1.5x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 2x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 3x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 4x"},"classes":[]},{"id":53420,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/06\/25\/containerize-a-blazor-net-application\/","url_meta":{"origin":53819,"position":1},"title":"Containerize a Blazor .NET Application","author":"CPI Staff","date":"June 25, 2025","format":false,"excerpt":"In this blog post, we will show you how to containerize a Blazor .NET application using native tools\u2014without relying on third-party scripts or complex setups. Microsoft .NET is one of the most popular development frameworks today, offering a wide range of deployment options. Running applications in containers and adopting microservices\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp 1x, \/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp 1.5x, \/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp 2x, \/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp 3x, \/wp-content\/uploads\/2025\/02\/How-to-Add-Bootstrap-to-a-.NET-Blazor-9-Web-Application.webp 4x"},"classes":[]},{"id":53803,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/11\/the-benefits-of-using-docker-compose-for-teams-and-projects\/","url_meta":{"origin":53819,"position":2},"title":"The Benefits of Using Docker Compose for Teams and Projects","author":"CPI Staff","date":"September 11, 2025","format":false,"excerpt":"Learn how Docker Compose streamlines multi-container development, testing, and CI. Practical steps, examples, and best practices for technical teams.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 1x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 1.5x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 2x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 3x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 4x"},"classes":[]},{"id":53794,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/10\/how-to-share-volumes-between-docker-containers\/","url_meta":{"origin":53819,"position":3},"title":"How to Share Volumes Between Docker Containers","author":"CPI Staff","date":"September 10, 2025","format":false,"excerpt":"Learn practical ways to share data between Docker containers using named volumes, bind mounts and Compose, with clear steps, permissions guidance, and security tips for reliable, high\u2011performance sharing.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png 1x, \/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png 1.5x, \/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png 2x, \/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png 3x, \/wp-content\/uploads\/2025\/09\/how-to-share-volumes-between-docker-containers-safely-and-reliably.png 4x"},"classes":[]},{"id":53777,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/03\/keep-docker-containers-running-prevent-common-exits\/","url_meta":{"origin":53819,"position":4},"title":"Keep Docker Containers Running: Prevent Common Exits","author":"CPI Staff","date":"September 3, 2025","format":false,"excerpt":"Learn why containers exit and practical ways to keep them alive. From foreground processes to restart policies, get clear steps for dev and production.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png 1x, \/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png 1.5x, \/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png 2x, \/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png 3x, \/wp-content\/uploads\/2025\/09\/keep-docker-containers-running-prevent-exits-in-production-and-dev.png 4x"},"classes":[]},{"id":53820,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/host-and-run-a-website-inside-docker-for-fast-portable-deploys\/","url_meta":{"origin":53819,"position":5},"title":"Host and Run a Website inside Docker for Fast, Portable Deploys","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"Learn how to containerise, serve, and secure a website with Docker. From first run to production-ready patterns, this guide covers images, volumes, networks, and TLS.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 1x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 1.5x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 2x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 3x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 4x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=53819"}],"version-history":[{"count":2,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53819\/revisions"}],"predecessor-version":[{"id":53828,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53819\/revisions\/53828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media\/53821"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=53819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=53819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=53819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}