{"id":53790,"date":"2025-09-08T16:33:34","date_gmt":"2025-09-08T06:33:34","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53790"},"modified":"2025-09-08T16:33:36","modified_gmt":"2025-09-08T06:33:36","slug":"keep-net-app-running-in-docker","status":"publish","type":"post","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","title":{"rendered":"Keep .NET App Running in Docker"},"content":{"rendered":"\n<p>In this blog post Keep .NET App Running in Docker we will walk through how to containerise a .NET application, start it automatically when the container launches, and keep it running reliably.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Containers shine when you want consistent, repeatable runtime environments. Docker gives you a lightweight, portable unit to ship and run your .NET service anywhere. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-high-level-overview\">High-level overview<\/h2>\n\n\n\n<p>Running a .NET app \u201call the time\u201d in Docker means two things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start it automatically when the container starts (using the image\u2019s entrypoint).<\/li>\n\n\n\n<li>Keep it alive with sensible restart policies and health checks.<\/li>\n<\/ul>\n\n\n\n<p>Docker images package your app and its runtime. Containers are running instances of those images. In each container, your application is PID 1\u2014the primary foreground process. If it exits, the container stops. So the right way to keep a .NET app running is to launch the app in the foreground, let Docker manage the process lifecycle, and rely on Docker policies to restart the container on failures or host restarts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-technology-behind-it\">The technology behind it<\/h2>\n\n\n\n<p>Several core Docker and .NET concepts make this work:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Images and layers<\/strong>: Your Dockerfile defines steps to build an image. Each step creates a layer you can cache and reuse.<\/li>\n\n\n\n<li><strong>ENTRYPOINT and CMD<\/strong>: These define what process runs when the container starts. For .NET, that\u2019s usually <code>dotnet YourApp.dll<\/code>.<\/li>\n\n\n\n<li><strong>Foreground process model<\/strong>: Containers aren\u2019t virtual machines. They run a single primary process in the foreground. When that process ends, the container stops.<\/li>\n\n\n\n<li><strong>Signals and graceful shutdown<\/strong>: Docker sends <code>SIGTERM<\/code> then <code>SIGKILL<\/code> on stop. ASP.NET Core and .NET\u2019s Generic Host respond to <code>SIGTERM<\/code> and shut down gracefully by default.<\/li>\n\n\n\n<li><strong>Logging<\/strong>: Write logs to stdout\/stderr. Docker captures these so you can use <code>docker logs<\/code> or forward them to a central system.<\/li>\n\n\n\n<li><strong>Health checks and restart policies<\/strong>: Health checks declare when your app is healthy. Restart policies tell Docker how to react when a container exits.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-create-a-minimal-net-web-api\">Create a minimal .NET web API<\/h2>\n\n\n\n<p>We\u2019ll create a tiny ASP.NET Core app that exposes a health endpoint and listens on port 8080.<\/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-68951ddd39bd3ed4a9639fbf53924f55\"><code>\/\/ Program.cs (.NET 8 minimal API)\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.Extensions.Hosting;\n\nvar builder = WebApplication.CreateBuilder(args);\nvar app = builder.Build();\n\napp.MapGet(\"\/\", () => Results.Ok(new { message = \"Hello from Dockerized .NET\" }));\napp.MapGet(\"\/health\", () => Results.Ok(\"ok\"));\n\napp.Run();<\/code><\/pre>\n\n\n\n<p>Ensure your project file references .NET 8 LTS (or your target LTS):<\/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-ee9a734ee13c9ae9da2fdf796eefef29\"><code>&lt;Project Sdk=\"Microsoft.NET.Sdk.Web\">\n  &lt;PropertyGroup>\n    &lt;TargetFramework>net8.0&lt;\/TargetFramework>\n    &lt;Nullable>enable&lt;\/Nullable>\n    &lt;ImplicitUsings>enable&lt;\/ImplicitUsings>\n  &lt;\/PropertyGroup>\n&lt;\/Project><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-build-a-production-friendly-docker-image\">Build a production-friendly Docker image<\/h2>\n\n\n\n<p>Use a multi-stage Dockerfile to keep the final image small, create a non-root user, and expose port 8080. We\u2019ll install <code>curl<\/code> to support a simple in-container health check. If you prefer a leaner image, you can omit curl and rely on external checks.<\/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-d9d70b7a7ae768df5c4d93f50891c0c3\"><code># Dockerfile\n# 1) Build stage\nFROM mcr.microsoft.com\/dotnet\/sdk:8.0 AS build\nWORKDIR \/src\n\n# copy csproj and restore as a distinct layer for better caching\nCOPY .\/WebDemo.csproj .\/\nRUN dotnet restore\n\n# copy the rest and publish\nCOPY . .\/\nRUN dotnet publish -c Release -o \/app\/publish --no-restore\n\n# 2) Runtime stage\nFROM mcr.microsoft.com\/dotnet\/aspnet:8.0 AS runtime\nWORKDIR \/app\n\n# Optional: install curl for HEALTHCHECK\nRUN apt-get update \\ \n    &amp;&amp; apt-get install -y --no-install-recommends curl \\ \n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\n# Create unprivileged user\nRUN useradd -m -u 10001 appuser\n\n# Copy published artifacts\nCOPY --from=build \/app\/publish .\n\n# Configure ASP.NET Core to listen on 8080\nENV ASPNETCORE_URLS=http:\/\/0.0.0.0:8080 \\\n    DOTNET_EnableDiagnostics=0\n\nEXPOSE 8080\n\n# Simple health check hitting the \/health endpoint\nHEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \\\n  CMD curl -f http:\/\/127.0.0.1:8080\/health || exit 1\n\n# Drop privileges\nUSER appuser\n\n# Run the app in the foreground when the container starts\nENTRYPOINT &#91;\"dotnet\", \"WebDemo.dll\"]<\/code><\/pre>\n\n\n\n<p>Key details:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <strong>ENTRYPOINT<\/strong> ensures your .NET app is PID 1 and runs in the foreground.<\/li>\n\n\n\n<li><strong>USER appuser<\/strong> avoids running as root in production.<\/li>\n\n\n\n<li><strong>HEALTHCHECK<\/strong> helps orchestrators know when to restart the container.<\/li>\n\n\n\n<li><strong>ASPNETCORE_URLS<\/strong> binds to 0.0.0.0 so traffic from the host can reach the app.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-build-and-run-the-container\">Build and run the container<\/h2>\n\n\n\n<p>From the folder containing your Dockerfile and project:<\/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-9ed8345a7363df9b405619ef66bd82cd\"><code># Build the image\ndocker build -t webdemo:1.0 .\n\n# Run detached, publish port 8080, and auto-restart unless stopped\ndocker run -d \\\n  --name webdemo \\\n  -p 8080:8080 \\\n  --restart unless-stopped \\\n  webdemo:1.0\n\n# Verify logs and test\ndocker logs -f webdemo\ncurl http:\/\/localhost:8080\/<\/code><\/pre>\n\n\n\n<p>If the app exits unexpectedly, Docker restarts it due to the <code>--restart unless-stopped<\/code> policy. For servers that reboot, the container comes back up automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-keep-it-running-the-right-way\">Keep it running the right way<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-use-docker-restart-policies\">Use Docker restart policies<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--restart no<\/code>: default; don\u2019t restart.<\/li>\n\n\n\n<li><code>--restart on-failure[:max-retries]<\/code>: restart on non-zero exit.<\/li>\n\n\n\n<li><code>--restart unless-stopped<\/code>: restart always unless you manually stop it.<\/li>\n\n\n\n<li><code>--restart always<\/code>: always restart\u2014even after manual stop (less common for services you might stop by hand).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-expose-a-health-endpoint\">Expose a health endpoint<\/h3>\n\n\n\n<p>The <code>\/health<\/code> route we added is a simple way for Docker (and load balancers) to confirm the app is responsive. In real apps, use ASP.NET Core Health Checks to test dependencies like databases or queues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-log-to-stdout-and-stderr\">Log to stdout and stderr<\/h3>\n\n\n\n<p>Don\u2019t write logs to local files in the container. Use console logging so Docker can capture and rotate them. In production, ship them to a central logging system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-graceful-shutdown\">Graceful shutdown<\/h3>\n\n\n\n<p>.NET\u2019s Generic Host handles <code>SIGTERM<\/code> gracefully. If you need to run cleanup code on shutdown, hook into <code>IHostApplicationLifetime<\/code>:<\/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-1ac7c65174ab96651ee30fdb06c60264\"><code>\/\/ Example: register shutdown callbacks\nusing Microsoft.Extensions.Hosting;\n\nvar builder = WebApplication.CreateBuilder(args);\nvar app = builder.Build();\n\nvar lifetime = app.Services.GetRequiredService&lt;IHostApplicationLifetime&gt;();\nlifetime.ApplicationStopping.Register(() =&gt; Console.WriteLine(\"Shutting down...\"));\n\napp.MapGet(\"\/\", () =&gt; \"Hello\");\napp.Run();\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-use-docker-compose-for-daily-workflows\">Use Docker Compose for daily workflows<\/h2>\n\n\n\n<p>Compose lets you describe your app\u2019s runtime settings in a file, then start\/stop with one command. Great for dev and single-host deployments.<\/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-62c694580fd023b18367224d76b6da80\"><code># docker-compose.yml\nversion: \"3.8\"\nservices:\n  web:\n    build: .\n    image: cloudproinc\/webdemo:1.0\n    ports:\n      - \"8080:8080\"\n    environment:\n      - ASPNETCORE_ENVIRONMENT=Production\n    restart: unless-stopped\n    healthcheck:\n      test: &#91;\"CMD-SHELL\", \"curl -f http:\/\/localhost:8080\/health || exit 1\"]\n      interval: 30s\n      timeout: 3s\n      retries: 3\n      start_period: 20s\n<\/code><\/pre>\n\n\n\n<p>Run it with:<\/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-4f2a360baf32b29219d48ee7f8e7536c\"><code>docker compose up -d<\/code><\/pre>\n\n\n\n<p>To view logs and status:<\/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-07d27a0d9c513dff2316c74f6528bc9b\"><code>docker compose logs -f\ndocker compose ps<\/code><\/pre>\n\n\n\n<p>In production, Compose is fine for a single host. At scale, consider Kubernetes, Amazon ECS, or Azure Container Apps for orchestration, rolling updates, and auto-scaling.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-always-on-background-jobs-with-net-worker\">Always-on background jobs with .NET Worker<\/h2>\n\n\n\n<p>If you\u2019re building a long-running worker (not HTTP), use the .NET Worker template. It runs until cancelled, which is perfect for containers:<\/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-29506f2b127e0d249ca5ef6004fbfee9\"><code># Create a worker project\n dotnet new worker -o WorkerDemo\n\n# Program.cs (simplified)\nusing Microsoft.Extensions.Hosting;\nusing Microsoft.Extensions.Logging;\n\nHost.CreateDefaultBuilder(args)\n    .ConfigureLogging(lb =&gt; lb.AddSimpleConsole())\n    .ConfigureServices(services =&gt; services.AddHostedService&lt;TimedWorker&gt;())\n    .Build()\n    .Run();\n\npublic sealed class TimedWorker : BackgroundService\n{\n    protected override async Task ExecuteAsync(CancellationToken stoppingToken)\n    {\n        while (!stoppingToken.IsCancellationRequested)\n        {\n            Console.WriteLine($\"Worker heartbeat: {DateTimeOffset.UtcNow}\");\n            await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>The Dockerfile pattern is the same\u2014just set the <code>ENTRYPOINT<\/code> to run the worker DLL. It will keep running until Docker sends <code>SIGTERM<\/code> or the process fails.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wrap-up\">Wrap-up<\/h2>\n\n\n\n<p>That\u2019s the practical path to keep a .NET app running in Docker:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Write a .NET app that runs in the foreground and exposes a health endpoint.<\/li>\n\n\n\n<li>Build a multi-stage image with an <code>ENTRYPOINT<\/code> that launches your app.<\/li>\n\n\n\n<li>Run it with a sensible <code>--restart<\/code> policy so it stays up.<\/li>\n\n\n\n<li>Add health checks and logs to stdout for observability.<\/li>\n\n\n\n<li>Use Docker Compose for convenient start\/stop and configuration.<\/li>\n<\/ol>\n\n\n\n<p>Follow these patterns and your .NET services will start cleanly, survive restarts, and run reliably\u2014without hacks or heavyweight infrastructure.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/03\/keep-docker-containers-running-prevent-common-exits\/\">Keep Docker Containers Running: Prevent Common Exits<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/06\/30\/run-azure-powershell-cmdlets-using-docker-containers\/\">Run Azure PowerShell cmdlets using Docker Containers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/04\/how-to-fix-the-critical-error-on-azure-wordpress-web-app\/\">How to Fix the &#8216;Critical Error&#8217; on Azure WordPress Web App<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/25\/run-neo4j-with-docker-inside-github-codespaces\/\">Run Neo4j with Docker inside GitHub Codespaces<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/06\/25\/containerize-a-blazor-net-application\/\">Containerize a Blazor .NET Application<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to containerise a .NET app, start it automatically, and keep it running with Docker and Docker Compose\u2014production-friendly, developer-happy.<\/p>\n","protected":false},"author":1,"featured_media":53791,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Keep .NET App Running in Docker","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.","_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-53790","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>Keep .NET App Running in Docker - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.\" \/>\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\/08\/keep-net-app-running-in-docker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keep .NET App Running in Docker\" \/>\n<meta property=\"og:description\" content=\"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-08T06:33:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-08T06:33:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\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\\\/08\\\/keep-net-app-running-in-docker\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Keep .NET App Running in Docker\",\"datePublished\":\"2025-09-08T06:33:34+00:00\",\"dateModified\":\"2025-09-08T06:33:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/\"},\"wordCount\":847,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png\",\"articleSection\":[\".NET\",\"Blog\",\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/\",\"url\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/\",\"name\":\"Keep .NET App Running in Docker - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png\",\"datePublished\":\"2025-09-08T06:33:34+00:00\",\"dateModified\":\"2025-09-08T06:33:36+00:00\",\"description\":\"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/08\\\/keep-net-app-running-in-docker\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Keep .NET App Running in Docker\"}]},{\"@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":"Keep .NET App Running in Docker - CPI Consulting","description":"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.","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\/08\/keep-net-app-running-in-docker\/","og_locale":"en_US","og_type":"article","og_title":"Keep .NET App Running in Docker","og_description":"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.","og_url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","og_site_name":"CPI Consulting","article_published_time":"2025-09-08T06:33:34+00:00","article_modified_time":"2025-09-08T06:33:36+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.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\/08\/keep-net-app-running-in-docker\/#article","isPartOf":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Keep .NET App Running in Docker","datePublished":"2025-09-08T06:33:34+00:00","dateModified":"2025-09-08T06:33:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/"},"wordCount":847,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","articleSection":[".NET","Blog","Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","name":"Keep .NET App Running in Docker - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","datePublished":"2025-09-08T06:33:34+00:00","dateModified":"2025-09-08T06:33:36+00:00","description":"Discover the best practices to keep .NET app running in Docker. Ensure consistent performance with health checks and settings.","breadcrumb":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#primaryimage","url":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","contentUrl":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudproinc.azurewebsites.net\/"},{"@type":"ListItem","position":2,"name":"Keep .NET App Running in Docker"}]},{"@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\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","jetpack-related-posts":[{"id":53420,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/06\/25\/containerize-a-blazor-net-application\/","url_meta":{"origin":53790,"position":0},"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":53777,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/03\/keep-docker-containers-running-prevent-common-exits\/","url_meta":{"origin":53790,"position":1},"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":53803,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/11\/the-benefits-of-using-docker-compose-for-teams-and-projects\/","url_meta":{"origin":53790,"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":53819,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","url_meta":{"origin":53790,"position":3},"title":"Build Lean Reliable .NET Docker Images for Production","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"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.","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\/how-to-build-lean-reliable-net-docker-images-for-production.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 1x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 1.5x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 2x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 3x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 4x"},"classes":[]},{"id":53428,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/06\/30\/run-azure-powershell-cmdlets-using-docker-containers\/","url_meta":{"origin":53790,"position":4},"title":"Run Azure PowerShell cmdlets using Docker Containers","author":"CPI Staff","date":"June 30, 2025","format":false,"excerpt":"In this blog post, we\u2019ll show you how to run Azure PowerShell cmdlets using Docker containers. Table of contentsPrerequisitesPull the Azure PowerShell Docker ImageRun the Container and Connect to AzureRunning Scripts from Your Local Machine Azure PowerShell provides a familiar PowerShell interface to manage Azure resources and infrastructure. It enables\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/microsoft-azure\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png 1x, \/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png 1.5x, \/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png 2x, \/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png 3x, \/wp-content\/uploads\/2025\/06\/run-auzre-powershell-using-docker.png 4x"},"classes":[]},{"id":53823,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/connecting-to-a-running-container-terminal\/","url_meta":{"origin":53790,"position":5},"title":"Connecting to a Running Container Terminal","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"Learn practical ways to attach a shell to running containers in Docker and Kubernetes, when to use them, and how to stay safe in 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\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png 1x, \/wp-content\/uploads\/2025\/09\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png 1.5x, \/wp-content\/uploads\/2025\/09\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png 2x, \/wp-content\/uploads\/2025\/09\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png 3x, \/wp-content\/uploads\/2025\/09\/connecting-to-a-running-container-terminal-in-docker-and-kubernetes.png 4x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53790","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=53790"}],"version-history":[{"count":1,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53790\/revisions"}],"predecessor-version":[{"id":53792,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53790\/revisions\/53792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media\/53791"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=53790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=53790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=53790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}