65

I'm new to ASP.NET Core and docker. I've created a simple ASP.NET Core 2.0 app and try to use docker with it on Windows. However, I get this error:

Your Docker server host is configured for 'Linux', however the docker-compose project targets 'Windows'.

Although it seems to be pretty informative error, I can't find where to 'configure host for Windows'

5 Answers 5

94

It is docker-compose.dcproj file where you can set up the OS you want to target:

<DockerTargetOS>Linux</DockerTargetOS>

To switch docker daemon to the same OS you can use Docker tray icon or Docker Settings window (accessible from the same menu):
enter image description here

10
  • 3
    I get this same error but I actually want to target Linux--not Windows. What is the fix for that situation? Aug 1, 2018 at 1:57
  • @AnthonyGatlin you just need to have the same OS in both places: your docker-compose project and your Docker machine. Check which one is incorrect and fix it. I have never used Windows containers, but I suppose it will be something like Switch back to normal Linux containers in docker tray menu. Aug 1, 2018 at 8:31
  • I am pretty sure that running under the same OS is not necessary. I am developing on Windows but will deploy to Linux. I can actually access Linux containers somewhat seamlessly through a VM created and managed by Docker for Windows. My error magically went away after a reboot and recreation of my docker files in my Visual Studio project. I am deploying to Linux containers again under my Windows machine. Aug 1, 2018 at 9:58
  • 1
    you can edit the .csproj file and change the <DockerTargetOS>Linux</DockerTargetOS> and save. it will work. Jun 23, 2020 at 12:48
  • 2
    Unless its obvious you should also have added orchestration to your project by right clicking selecting add > orchestrations > docker-compose It is indeed possible to have this issue without having orchestration setup, and by having the orchestration setup that is one way we can now set the Target OS Jul 29, 2020 at 10:46
24

Well basically the answer of Celestin Bochis and Pavel Agarkov are great. However since .net core 2.2 at least, the os of docker is stored in the .csproj file.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    ...
   </PropertyGroup>

   ...
</Project>

And also don't forget to modify your docker file. The images should be the correct one. For .net core 2.2 That is :

Linux:
Microsoft/dotnet:2.2-aspnetcore-runtime AS base
microsoft/dotnet:2.2-sdk AS build

Windows:
microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803
microsoft/dotnet:2.2-sdk-nanoserver-1803
2
  • This was exactly what I was looking for, thank you!
    – Jim
    Mar 29, 2019 at 22:21
  • My docker compose as set to Linux but the problem was even though I chose Linux as the target OS when creating the Core Web Applications Visual Studio still put Wndows as the default target OS in the CS project. Jun 5, 2019 at 20:05
12

Make sure to choose the correct OS when you Enable docker support:

OS dropdown

Your docker daemon has to target Linux containers as well.

5
  • 1
    From review: this does not really answer the question, it looks more like a comment.
    – toti08
    Nov 13, 2018 at 10:10
  • @toti08 Trust me this is exactly what OP was looking for. I had the same problem yesterday and this got me through it. Nov 13, 2018 at 10:39
  • 1
    @VishvaDave it's just a link to an image that I've inlined. Answer is fine.
    – Nick
    Nov 13, 2018 at 11:18
  • @Nick Ohh sorry i was doing forum review and i thought this is the link for answer.
    – Vidhi Dave
    Nov 13, 2018 at 11:20
  • 1
    @VishvaDave I was also doing it from review. I've marked it OK so should cancel your delete vote...
    – Nick
    Nov 13, 2018 at 11:21
3

If the docker is running on the windows machine then you need to change the value of "DockerTargetOS" should be "Windows" in .dcproj file.

Unload the docker project from visual studio and edit the project and set the value "Windows" to "DockerTargetOS".

<DockerTargetOS>Windows</DockerTargetOS>
2
  • I found <DockerTargetOS>Windows</DockerTargetOS> in .csproj and it works.when I change from windows to Linux, My container configured for linux. Mar 16, 2021 at 19:20
  • The unload/reload of the project worked for me! I had it set to Linux, and the dockerfile and the project file were all set to Linux properly, but I still got the error about the target OS not found, even though Docker is running in Linux mode. I unloaded the project and reloaded it and now it works fine!
    – ChrisC
    Oct 13, 2021 at 17:11
0

I got this error when I created the project to target Windows and later wanted to switch it to target to Linux. The steps are a little bit more involved if you want to use Linux containers instead:

  1. Unload docker-compose, edit the DockerTargetOS to Linux, then reload the project
  2. Go to docker-compose.yml. Make sure that the backslash is a forward slash. Should look like "WebApplication/Dockerfile"
  3. On the Dockerfile, for the base use "microsoft/aspnetcore:2.0" and for build, use "microsoft/aspnetcore-build:2.0" so it should look like this:

    FROM microsoft/aspnetcore:2.0 AS base
    WORKDIR /app
    EXPOSE 80
    
    FROM microsoft/aspnetcore-build:2.0 AS build
    WORKDIR /src
    COPY WebApplication7/WebApplication.csproj WebApplication/
    RUN dotnet restore WebApplication/WebApplication.csproj
    COPY . .
    WORKDIR /src/WebApplication
    RUN dotnet build WebApplication.csproj -c Release -o /app
    
  4. Right click on the Docker tray icon > settings > Shared Drives > pick the drive your project resides in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.