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

Sign up to request clarification or add additional context in comments.

10 Comments

I get this same error but I actually want to target Linux--not Windows. What is the fix for that situation?
@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.
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.
you can edit the .csproj file and change the <DockerTargetOS>Linux</DockerTargetOS> and save. it will work.
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
|
23

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 Comments

This was exactly what I was looking for, thank you!
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.
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 Comments

From review: this does not really answer the question, it looks more like a comment.
@toti08 Trust me this is exactly what OP was looking for. I had the same problem yesterday and this got me through it.
@VishvaDave it's just a link to an image that I've inlined. Answer is fine.
@Nick Ohh sorry i was doing forum review and i thought this is the link for answer.
@VishvaDave I was also doing it from review. I've marked it OK so should cancel your delete vote...
2

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 Comments

I found <DockerTargetOS>Windows</DockerTargetOS> in .csproj and it works.when I change from windows to Linux, My container configured for linux.
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!
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.