skip to Main Content

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…

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search