10

I'm trying to build the most basic web Api application using VS2019 along with docker. Basically it is just the demo app provided by VS. I'm ending up with below error:

Severity Code Description Project File Line Suppression State Error CTC1014 Docker command failed with exit code 1. hcsshim::PrepareLayer - failed failed in Win32: Incorrec

Below my dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["RegexTesterApi/RegexTesterApi.csproj", "RegexTesterApi/"]
RUN dotnet restore "RegexTesterApi/RegexTesterApi.csproj"
COPY . .
WORKDIR "/src/RegexTesterApi"
RUN dotnet build "RegexTesterApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "RegexTesterApi.csproj" -c Release -o /app/publish

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

Well this is the auto generated dockerfile. But it looks pretty ok to me (also I'm new to docker).

What is actually causing the error.

2
  • Might not be too helpful but there an issue raised about this with a couple of purposed workarounds but nothing solid yet Commented Feb 11, 2020 at 16:17
  • If running from within Visual Studio 2019 the error console has an arrow > to the left of the error message; clicking this expands the error for a more detailed description. Commented May 3, 2020 at 23:39

4 Answers 4

6

My project was being run in release mode when it should have been running in debug mode:

Here's how you change it in VS2019

It must be related to optimization by release build configurations in conflict with Docker. Not sure which one though.

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

3 Comments

Well, I still could not run it in neither release nor debug. Thing is it works with Linux container but not with windows
In my case, it had to do with the paths in the COPY and WORKDIR commands, which specified a leading "src/", which was not needed.
@riki Why is it marked as the solution then?
0

I faced this issue too, but with .net core 2.1. I'm not sure why it's working but, If this solution is available for you then try the following:

  1. Restart Docker Desktop (This solution is offered in the output window)
  2. Change the docker file.

I replaced this

FROM mcr.microsoft.com/dotnet/runtime:2.1 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR /src

to

FROM mcr.microsoft.com/dotnet/core/runtime:2.1-alpine AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-alpine AS build
WORKDIR /src

Then debug started to work fine even after changing the docker file to start variant, including stops on breakpoints. And my configuration has one additional difference: I use Debug argument in the docker file and use Debug in Solution configuration

RUN dotnet build "DebugLinux.csproj" -c Debug -o /app/build

Comments

0

This error migh be raised when the dockerfile in your project don't match the Target Framework in the project settings.

Just delete your dockerfile and create a new one and this will fix the problem if this is the issue.

Comments

0

Remove your Docker file from root. Also remove these two lines from the .csproj file:

<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
    <DockerLaunchUrl>http://{ServiceIPAddress}</DockerLaunchUrl>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.