From 3feba1b54e6d7b6c946907da881423aa203efb68 Mon Sep 17 00:00:00 2001 From: Ivar Nesje Date: Sun, 19 Feb 2023 22:05:23 +0100 Subject: [PATCH] Fix a few issues with the Dockerfile I tried to work on some sort of automated testing and ran into a really strange issue with dotnet in docker. The docker container did not work with `--env DOTNET_ENVIRONMENT=Development`. After lots of guesswork I found that deleting the `wwwroot` folder fixed the issue. It turns out that when you do a separate `build` step it generates `App.staticwebassets.runtime.json` with full absolute path to the `wwwroot` folder, and it gets included in the `publish` result. In the `build` step the path is `/App/wwwroot`, but in final the name was `/app/wwwroot`. This fixes 3 issues * A separate `restore` step makes for faster iteration when building repeatedly locally. * Consistent folder name `app` vs `App` in build container vs final container * A separate `dotnet build` step doesn't really make much sense, and the resulting `App.staticwebassets.runtime.json` is apparently just causing issues. --- src/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index 64c805d9..1fe7f41a 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,16 +1,16 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build -WORKDIR / +WORKDIR /App -COPY /App ./App +COPY /App/App.csproj . +RUN dotnet restore App.csproj -WORKDIR /App +COPY /App . -RUN dotnet build App.csproj --configuration Release --output /app_output RUN dotnet publish App.csproj --configuration Release --output /app_output FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS final EXPOSE 5005 -WORKDIR /app +WORKDIR /App COPY --from=build /app_output . ENV ASPNETCORE_URLS=