dockerdocker-composedockerfile

ERROR [build 6/6] RUN dotnet publish "" -c Release -o /app/publish


I'm building an image for Web API .Net 5

My folder directory looks like this

D:\Working\Phong_Nguyen_Super_Hero\Weather Forecast Application\WeatherForecast-main\TLY.WeatherForecast
                               |- TLY.WeatherForecast.sln
                               |- Dockerfile
                               |- .dockerignore
                               |- TLY.WeatherForecast

And my Dockerfile content looks like this

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

ENV ASPNETCORE_URLS=http://+:80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["TLY.WeatherForecast/TLY.WeatherForecast.csproj", "TLY.WeatherForecast/"]
RUN dotnet restore "TLY.WeatherForecast/TLY.WeatherForecast.csproj"
COPY . .
RUN dotnet publish "TLY.WeatherForecast.csproj" -c Release -o /app/publish

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

And when I run this command

docker build -t phongnguyen94/weatherforecast_api:latest .

I got errors below

> [+] Building 110.7s (14/15)  => [internal] load build definition from
> Dockerfile                                                            
=> transferring dockerfile: 569B                                                                                                                               
=> [internal] load .dockerignore                                                                                                                                  
=> transferring context: 388B                                                                                                                                  
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0                                      
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0                                   
=> [internal] load build context                                                                                                                                 
=> transferring context: 4.46MB                                                                                                                                
=> [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:5.0@sha256:c0cc95b0d87a31401763f8c7b2a25aa106e7b45bfcaa2f302dc9d0ff5ab93fa2
=> => resolve mcr.microsoft.com/dotnet/aspnet:5.0@sha256:c0cc95b0d87a31401763f8c7b2a25aa106e7b45bfcaa2f302dc9d0ff5ab93fa2
=> extracting sha256:1396b16d0d87d441988017c78df3fe711ae12f60cce661c2a9a004bdce6f4ee3
=> [build 1/6] FROM mcr.microsoft.com/dotnet/sdk:5.0@sha256:85ea9832ae26c70618418cf7c699186776ad066d88770fd6fd1edea9b260379a
=> resolve mcr.microsoft.com/dotnet/sdk:5.0@sha256:85ea9832ae26c70618418cf7c699186776ad066d88770fd6fd1edea9b260379a
=> extracting sha256:9887694812e570c8e6fab2fbffd327127283e4360cce25677d9ee7a7c309162d
=> [base 2/2] WORKDIR /app                                                                                                                                        
=> [final 1/2] WORKDIR /app                                                                                                                                       
=> [build 2/6] WORKDIR /src                                                                                                                                       
=> [build 3/6] COPY [TLY.WeatherForecast/TLY.WeatherForecast.csproj, TLY.WeatherForecast/]
=> [build 4/6] RUN dotnet restore "TLY.WeatherForecast/TLY.WeatherForecast.csproj"                      
=> [build 5/6] COPY . .                                                                                                                                           
=> ERROR [build 6/6] RUN dotnet publish "TLY.WeatherForecast.csproj" -c Release -o /app/publish

------
 > [build 6/6] RUN dotnet publish "TLY.WeatherForecast.csproj" -c Release -o /app/publish:
#14 0.578 Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
#14 0.578 Copyright (C) Microsoft Corporation. All rights reserved.
#14 0.578
#14 0.579 MSBUILD : error MSB1009: Project file does not exist.
#14 0.579 Switch: TLY.WeatherForecast.csproj

Solution

  • I've changed the Dockerfile content this line then it works fine

    From

    RUN dotnet publish "TLY.WeatherForecast.csproj" -c Release -o /app/publish
    

    To

    RUN dotnet publish "TLY.WeatherForecast/TLY.WeatherForecast.csproj" -c Release -o /app/publish
    

    Because I've placed the Dockerfile file outside the project. So I need to redirect into TLY.WeatherForecast folder.