Search code examples
c#docker.net-core.net-6.0docker-machine

Your Docker server host is configured for 'Linux', however your project targets 'Windows' .Net 6


I have created the .net core web api in Visual studio 2022 with docker enabled with selected OS as Windows. After building the code using Docker i am getting "Your Docker server host is configured for 'Linux', however your project targets 'Windows'"

Below is my docker file.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app

EXPOSE 80

EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ApacheKafka.Producer/ApacheKafka.Producer.csproj", "ApacheKafka.Producer/"]
RUN dotnet restore "ApacheKafka.Producer/ApacheKafka.Producer.csproj"
COPY . .
WORKDIR "/src/ApacheKafka.Producer"
RUN dotnet build "ApacheKafka.Producer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ApacheKafka.Producer.csproj" -c Release -o /app/publish 
/p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ApacheKafka.Producer.dll"]

In Container.targets its pointing to Windows OS

<DockerDefaultTargetOS Condition="'$(DockerDefaultTargetOS)' == 
''">Windows</DockerDefaultTargetOS>

Solution

  • In Container.targets, you are targeting your container type to Windows:

    <DockerDefaultTargetOS Condition="'$(DockerDefaultTargetOS)' == 
    ''">Windows</DockerDefaultTargetOS>
    

    However, your Docker instance is probably configured to host Linux containers. Either you should do one of the following:

    • Change <DockerDefaultTargetOS> to Linux (be sure that your container runs appropriately)
    • Configure Docker instance to Windows

    To change Docker Container Type to Windows Using Docker Desktop

    Here is a link to the Docker documentation outlining how to configure Docker using Docker Desktop: https://docs.docker.com/desktop/settings/windows/

    An easy way to switch container types is:

    1. Right-click Docker icon in your System Tray
    2. Click the Switch to Windows Containers... button

    Relevant Links

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