riki
riki

Reputation: 2393

Error CTC1014 Docker command failed with exit code 1 with dotnet core api

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.

Upvotes: 9

Views: 15521

Answers (3)

Seb
Seb

Reputation: 1230

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.

Upvotes: 0

Dimsa
Dimsa

Reputation: 281

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

Upvotes: 0

Rodrigo
Rodrigo

Reputation: 56

I ran into the very same error (CTC1014) in the past. I found out that my project was being run in "Release" mode, when it should have been running in "Debug" mode. So I would like to suggest this as a workaround.

Here's how you change it in VS2019

Of course, running your application in Release mode shouldn't be a problem. So I assumed it must have been related to some optimization employed by most release build configurations, in conflict with Docker. Not exactly sure which one, though.

Cheers! o/

Upvotes: 4

Related Questions