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>
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:
<DockerDefaultTargetOS>
to Linux (be sure that your container runs appropriately)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:
Switch to Windows Containers...
buttonHow do you change Docker OS Support for a .Net Core Web Application Project?