I read some documentation on how to setup a docker file for an asp.net core project. I have a rest api named dsi.rest.app and I try to create a dockerfile.
I followed tutorials and created a Dockerfile in the dsi.rest.app folder. The following folder is containing the solution i want to dockerise.
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /DockerSource
# Copy csproj and restore as distinct layers
COPY *.sln .
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build website
COPY /. ./
WORKDIR /DockerSource/dsi.rest.app
# RUN dotnet publish -c release -o /DockerOutput/dsi.rest.app --no-restore
RUN dotnet build "dsi.rest.app.csproj" -c Release -o /DockerOutput/dsi.rest.app --no-restore
# Final stage / image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /DockerOutput/dsi.rest.app
COPY --from=build /DockerOutput/dsi.rest.app ./
ENTRYPOINT ["dotnet", "dsi.rest.app.dll"]
I try to build the image:
docker build --pull -t dsi.rest.rest .
And I obtain an error message:
=> ERROR [build 8/8] RUN dotnet build "dsi.rest.app.csproj" -c Release -o /DockerOutput/dsi.rest.app --no-restore 0.5s
#15 0.505 MSBUILD : error MSB1009: Project file does not exist.
#15 0.505 Switch: dsi.rest.app.csproj
the project file is situated at the same level as the dockerfile. the csproj file is at the same folder level as the Dockerfile.
My csproj file contains the following information :
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>4b7e5335-798e-4066-a795-83e772338899</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
<PackageReference Include="MsgReader" Version="3.12.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
I ran the command : dotnet build "dsi.rest.app.csproj" -c Release -o /DockerOutput/dsi.rest.app --no-restore without any problem. It did generate my application in C:/DockerOutput/dsi.rest.app