DOTNET Docker Containers.

user1272047user1272047
6 min read

You can develop and run .NET applications within Docker containers on Linux using Microsoft's official .NET Docker images. These images are available for various .NET versions and are optimized for different development and production scenarios.

Getting Started with .NET Docker Containers:

  1. Install Docker:

    • Ensure Docker is installed on your Linux system. You can download it from the official Docker website.
  2. Pull the .NET SDK Image:

    • The .NET SDK image includes the necessary tools for building and running .NET applications. Pull the latest .NET SDK image using: ```bash docker pull mcr.microsoft.com/dotnet/sdk:8.0

        This command fetches the .NET 8.0 SDK image. For other versions, replace `8.0` with the desired version number. citeturn0search1
      
  3. Run a Container with the .NET SDK:

    • Start a container with an interactive terminal: ```bash docker run -it --rm mcr.microsoft.com/dotnet/sdk:8.0 bash

        This command opens a bash shell inside the container, allowing you to use the .NET CLI for development tasks.
      
  4. Develop Your Application:

    • Inside the container, you can create a new .NET application: ```bash dotnet new console -o MyApp cd MyApp dotnet run

        This sequence creates and runs a simple console application.
      
  5. Building and Running Applications:

    • For building and running applications, you can use multi-stage Docker builds to optimize the final image size. Here's an example Dockerfile for a .NET application: ```dockerfile

    • Use the SDK image to build the app

      FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY . . RUN dotnet publish -c Release -o out

    • Use the ASP.NET Core runtime image to run the app

      FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app COPY --from=build /app/out . ENTRYPOINT ["dotnet", "MyApp.dll"]

        This `Dockerfile` first builds the application using the SDK image and then uses the runtime image to run the application, resulting in a smaller final image. citeturn0search0
      

Additional Resources:

  • Official .NET Docker Images Documentation: Provides detailed information on available images and their usage. citeturn0search1

  • Development Workflow for Docker Apps: Offers guidance on developing Docker container-based applications with .NET. citeturn0search9

By leveraging these Docker images, you can effectively develop, test, and deploy .NET applications within a Linux environment.

Links

Favicon

Microsoft Learn

Official .NET Docker images - .NET | Microsoft Learn

When building inside a Docker container, the important aspects are the elements that are needed to compile your app. ... In the Docker model, there is no need for compilation from C# code, as there's when you run dotnet build or dotnet publish when using the build container. In this optimized image, you put only the binaries and other content ...

Favicon

Microsoft Learn

Containerize an app with Docker tutorial - .NET | Microsoft Learn

March 20, 2024 — Create the Dockerfile. The Dockerfile file is used by the docker build command to create a container image. This file is a text file named Dockerfile that doesn't have an extension.. Create a file named Dockerfile in the directory containing the .csproj and open it in a text editor. This tutorial uses the ASP.NET Core runtime image (which contains the .NET runtime image) and corresponds with ...

Favicon

Microsoft Learn

Development workflow for Docker apps - .NET | Microsoft Learn

September 9, 2024 — The above command will create a new container instance from the specified image, every time it's run. You can use the --name parameter to give a name to the container and then use docker start {name} (or use the container ID or automatic name) to run an existing container instance. Figure 5-9. Running a Docker container using the docker run command

Search Results

Favicon

Microsoft Learn

Development workflow for Docker apps - .NET | Microsoft Learn

September 9, 2024 — The above command will create a new container instance from the specified image, every time it's run. You can use the --name parameter to give a name to the container and then use docker start {name}...

Favicon

Microsoft Learn

Containerize an app with dotnet publish - .NET | Microsoft Learn

August 12, 2024 — The container port adds TCP or UDP ports to the list of known ports for the container. This enables container runtimes like Docker to map these ports to the host machine automatically. This is often u...

Favicon

Microsoft Learn

Run an ASP.NET Core app in Docker containers | Microsoft Learn

May 14, 2024 — ASP.NET Core Docker images. For this tutorial, you download an ASP.NET Core sample app and run it in Docker containers. The sample works with both Linux and Windows containers.

Favicon

Microsoft Learn

Containerize an app with Docker tutorial - .NET | Microsoft Learn

March 20, 2024 — Create the Dockerfile. The Dockerfile file is used by the docker build command to create a container image. This file is a text file named Dockerfile that doesn't have an extension.. Create a file nam...

Favicon

Docker

9 Tips for Containerizing Your .NET Application - Docker

July 17, 2022 — Over the last five years, .NET has maintained its position as a top framework among professional developers. In Stack Overflow’s 2022 Developer Survey, .NET ranked first in the “other framework and li...

Favicon

Daniel Donbavand

Running Docker Containers from within your .NET Core Application using ...

December 15, 2021 — Install-Package Docker.DotNet -version 3.125.2 Setting up Docker.DotNet Client. Using the Docker.DotNet library we are going to set up our client, this will allow us to interact with the docker engine...

Favicon

Microsoft Developer Blogs

Using .NET and Docker Together - .NET Blog - devblogs.microsoft.com

May 24, 2017 — Migrating .NET Framework Applications to Containers. Wouldn’t it be exciting if there was a tool to convert VHDs to Docker containers? At DockerCon 2017, there was much excitement around a tool design...

Favicon

Microsoft Learn

Official .NET Docker images - .NET | Microsoft Learn

When building inside a Docker container, the important aspects are the elements that are needed to compile your app. ... In the Docker model, there is no need for compilation from C# code, as there's...

Favicon

GitHub

dotnet/dotnet-docker: Docker images for .NET and the .NET Tools. - GitHub

The -p argument in these examples maps host port 8000 to container port 8080 (host:container mapping). The container will not be accessible without this mapping. ASP.NET Core can be configured to list...

Favicon

GitHub

GitHub - dotnet/Docker.DotNet: :whale: .NET (C#) Client Library for ...

PM> Install-Package Docker.DotNet. Visual Studio Right click to your project in Visual Studio, choose “Manage NuGet Packages” and search for ‘Docker.DotNet’ and click ‘Install’. (see NuGet Gallery.).N...

Favicon

GitHub

dotnet-docker/documentation/scenarios/installing-dotnet.md at main ...

Before doing all the work of authoring and maintaining a Dockerfile that installs .NET, it's worthwhile to stop and thoroughly analyze whether you actually do need a different base image than those pr...

Favicon

GitHub

microsoft/dotnet-framework-docker - GitHub

The repo for the official docker images for .NET Framework on Windows Server Core. - microsoft/dotnet-framework-docker. ... (WC

LINKS

http://learn.microsoft.com/en-us/dotnet/architecture/microservices/net-core-net-framework-containers/official-net-docker-images
http://learn.microsoft.com/en-us/dotnet/core/docker/build-container
http://learn.microsoft.com/en-us/dotnet/core/docker/docker-app-development-workflow
http://learn.microsoft.com/en-us/dotnet/core/docker/publish-container
http://learn.microsoft.com/en-us/dotnet/core/docker/run-aspnet-core-docker
http://learn.microsoft.com/en-us/dotnet/core/docker/tutorial
http://www.docker.com/blog/9-tips-for-containerizing-your-dotnet-application
http://www.danieldonbavand.com/docker-dotnet-library
http://devblogs.microsoft.com/dotnet/using-dotnet-and-docker-together
http://github.com/dotnet/dotnet-docker
http://github.com/dotnet/Docker.DotNet
http://github.com/dotnet/dotnet-docker/tree/main/documentation/scenarios
http://github.com/microsoft/dotnet-framework-docker
0
Subscribe to my newsletter

Read articles from user1272047 directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

user1272047
user1272047