How do you change Docker OS Support for a .Net Core Web Application Project? How do you change Docker OS Support for a .Net Core Web Application Project? docker docker

How do you change Docker OS Support for a .Net Core Web Application Project?


This turned out to be easy, and I did it through editing the csproj file: Changed <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS> to <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> and reload.

I am still not sure where you would do this from Visual Studio (if it possible).


If only one project is there in the solution, I would delete the project associated with docker-compose.dcproj and Dockerfile inside the API project. After that I would right click and again add docker support to that project.

This would create new dockerfile with linux base image.

And new dcproj will have linux mentioned

<DockerTargetOS>Linux</DockerTargetOS>


In my case, I am using a .Net Core 3.1 API project and just editing the project file didn't work. I also had to indicate that the docker image was different. This is what I did:

  1. On the Solution Explorer, Right click the project, select "Unload"

  2. Right click the project, edit it(The project file can also be edited outside. Even Right click, Add, Docker support worked once)

  3. As mentioned by others, change:

    < DockerDefaultTargetOS>Windows</ DockerDefaultTargetOS>

    To:

    < DockerDefaultTargetOS>Linux</ DockerDefaultTargetOS>

    (Only change "Windows" to "Linux")

  4. Change the image name. Edit the file called "Dockerfile". Change:

    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base

    To:

    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base

    I also changed the build name accordingly. Changed:

    FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build

    To:

    FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build

The image names may be different. Just make sure to change the Windows image to the Linux image.