TestContainers Exception: Docker.DotNet.DockerApiException : Docker API responded with status code=Conflict
Asked Answered
M

0

9

I have a .Net Core 6 Project which I am trying to setup integration tests for using TestContainers.

I am using a Dockerfile generated by Visual Studio and this builds my image and I am able to run the container locally and the web api works as expected but when I run the same DockerFile in a TestContainers project I get the exception :

Docker.DotNet.DockerApiException : Docker API responded with status code=Conflict, response={"message":"Container 51d3ead2c1f194aef0c5876cbc29affe89c81c40b142131cd037e6eba8f5e624 is not running"}

Here is my Dockerfile

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 /
COPY ./nuget.config /nuget.config
COPY ["MyProjectDir/MyProject.csproj", "MyProject/"]
COPY ["Common/Common.csproj", "Common/"]
RUN dotnet restore "MyProjectDir/MyProject.csproj"
COPY . .
WORKDIR "/MyProject"
RUN dotnet build "MyProject.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyProject.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

One thing I observed though is it seems the TestContainers instance is failing to run the final build stage of the Dockerfile as I only see the Publish Stage image when the process is completed and then get an exception.

Morin answered 30/3, 2023 at 14:25 Comment(1)
Any luck here? This started happening to me today.Bromidic

© 2022 - 2024 — McMap. All rights reserved.