Home > database >  Why does my docker configuration in ASP.NET not work?
Why does my docker configuration in ASP.NET not work?

Time:06-06

I have a problem when I try to start my .NET6 application in docker.

It tells me that there is no suitable 'main' function ; But when I start it without docker (with Kestrel server), it works perfectly.

Here is the 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 /src
COPY ["API.csproj", "API/"]
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build

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

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

The problem is on the line 12 (and maybe line if the line 12 pass correctly 15)

Here is the repo : https://gitea.gremy.ovh/gremy.ovh/gremy.ovh.git

If someone can help me, I don't know where the problem is...

CodePudding user response:

I can't reproduce your issue. Here are the commands I run (from an empty directory)

git clone https://gitea.gremy.ovh/gremy.ovh/gremy.ovh.git
cd gremy.ovh/
git submodule update --init --recursive
cd src/
docker build -t test .
docker run --rm -d -p 8080:80 test

The container builds and runs. I can't see any API endpoints in the code, so I can't test if the code does anything.

CodePudding user response:

I changed the location of Dockerfile into src folder. It works, it seems that the default configuration of Visual Studio and Rider when creating a project using Docker is not working as expected.

  • Related