I created a Visual Studio asp.net 8.0 Razor page solution with one project and choose ‘Enable Docker’. That ran fine in Visual Studio using run ‘container (Dockerfile)’. I was also able to successfully build the container using ‘docker build -t webapp1 .’
Then I added a second project to the solution and am not sure how to change Dockerfile. (Visual Studio run ‘container (Dockerfile)’ still works but my goal is to manually build from the Dockerfile myself.) I understand I have to move Dockerfile up to the project parent folder, namely, the solution folder. But when I run my build command I now get dozens of errors like this:
**level=error msg="Can't add file \\?\C:\Temp\TestDocker\WebApp1\Program.cs to tar: archive/tar: missed writing 1687312 bytes"**
Why does it insert \? before the file name? Please tell me what is wrong with the Dockerfile below.
P.S. this is my first Docker container and a learning experience – the ultimate goal is to transfer this Dockerfile to AWS and run the container there.
The folder structure is:
c:TempDockerTestWebApp1* (an asp.net 8.0 Razor page app)
c:TempDockerTestWebApi1* (a class library referenced by WebApp1)
c:TempDockerTestDockerfile
Here is the Dockerfile run using Powershell in c:TempDockerTest:
FROM mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY WebApp1/WebApp1.csproj ./WebApp1/
COPY WebApi1/WebApi1.csproj ./WebApi1/
RUN dotnet restore WebApp1/WebApp1.csproj
RUN dotnet restore WebApi1/WebApi1.csproj
COPY . ./
WORKDIR /src/.
RUN dotnet build WebApp1/WebApp1.csproj -c %BUILD_CONFIGURATION% -o /app/build
RUN dotnet build WebApi1/WebApi1.csproj -c %BUILD_CONFIGURATION% -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "WebApp1/WebApp1.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApp1.dll"]