dotnet / dotnet-docker

Docker images for .NET and the .NET Tools.
https://hub.docker.com/_/microsoft-dotnet
MIT License
4.49k stars 1.94k forks source link

Unable to build Docker-Container with Asp.Net 8.0 #5200

Closed Granock closed 8 months ago

Granock commented 9 months ago

Describe the Bug

When building my container on asp.net 8.0 the build fails at dotnet restore. The problem only occurs in docker, building the project directly through vs studio 2022 succeeds.

Steps to Reproduce

When using this docker-file (comments and final publish step removed)

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 5000
EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

COPY ["shared/.", "shared/."]
COPY ["core/.", "core/."]
WORKDIR /src/core

RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj"-c $BUILD_CONFIGURATION -o /app/build

docker fails at

RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"

with the error:

PS [pathToProject]> docker build . -f .\CoreApi_Dockerfile --no-cache
[+] Building 1.4s (14/17)                                                                                                                                                                                                                                                docker:default
 => [internal] load build definition from CoreApi_Dockerfile                                                                                                                                                                                                                       0.1s
 => => transferring dockerfile: 1.04kB                                                                                                                                                                                                                                             0.1s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0                                                                                                                                                                                                                  0.2s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0                                                                                                                                                                                                               0.2s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                  0.0s
 => => transferring context: 464B                                                                                                                                                                                                                                                  0.0s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:789045ecae51d62d07877994d567eff4442b7bbd4121867898ee7bf00b7241ea                                                                                                                                                    0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b246fc9a92feefe3aff49beb165fda4fc5a29122cd30768bafdc2d3e606c565c                                                                                                                                                      0.0s
 => [internal] load build context                                                                                                                                                                                                                                                  0.5s
 => => transferring context: 5.36kB                                                                                                                                                                                                                                                0.5s
 => CACHED [base 2/2] WORKDIR /app                                                                                                                                                                                                                                                 0.0s
 => CACHED [final 1/2] WORKDIR /app                                                                                                                                                                                                                                                0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                                                                                                                                                                                0.0s
 => [build 3/7] COPY [shared/., shared/.]                                                                                                                                                                                                                                          0.1s
 => [build 4/7] COPY [core/., core/.]                                                                                                                                                                                                                                              0.1s
 => [build 5/7] WORKDIR /src/core                                                                                                                                                                                                                                                  0.1s
 => ERROR [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"                                                                                                                                                                                                    0.3s
------
 > [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj":
0.293 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
0.293 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
------
CoreApi_Dockerfile:20
--------------------
  18 |     WORKDIR /src/core
  19 |
  20 | >>> RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
  21 |     RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj"-c $BUILD_CONFIGURATION -o /app/build
  22 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147

Output of docker version

Client: Cloud integration: v1.0.35+desktop.10 Version: 25.0.3 API version: 1.44 Go version: go1.21.6 Git commit: 4debf41 Built: Tue Feb 6 21:13:02 2024 OS/Arch: windows/amd64 Context: default

Server: Docker Desktop 4.27.2 (137060) Engine: Version: 25.0.3 API version: 1.44 (minimum version 1.24) Go version: go1.21.6 Git commit: f417435 Built: Tue Feb 6 21:14:25 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0

Output of docker info

Client: Version: 25.0.3 Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.12.1-desktop.4 Path: C:\Program Files\Docker\cli-plugins\docker-buildx.exe compose: Docker Compose (Docker Inc.) Version: v2.24.5-desktop.1 Path: C:\Program Files\Docker\cli-plugins\docker-compose.exe debug: Get a shell into any image or container. (Docker Inc.) Version: 0.0.24 Path: C:\Program Files\Docker\cli-plugins\docker-debug.exe dev: Docker Dev Environments (Docker Inc.) Version: v0.1.0 Path: C:\Program Files\Docker\cli-plugins\docker-dev.exe extension: Manages Docker extensions (Docker Inc.) Version: v0.2.21 Path: C:\Program Files\Docker\cli-plugins\docker-extension.exe feedback: Provide feedback, right in your terminal! (Docker Inc.) Version: v1.0.4 Path: C:\Program Files\Docker\cli-plugins\docker-feedback.exe init: Creates Docker-related starter files for your project (Docker Inc.) Version: v1.0.0 Path: C:\Program Files\Docker\cli-plugins\docker-init.exe sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.) Version: 0.6.0 Path: C:\Program Files\Docker\cli-plugins\docker-sbom.exe scout: Docker Scout (Docker Inc.) Version: v1.4.1 Path: C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 25.0.3 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Using metacopy: false Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 runc Default Runtime: runc Init Binary: docker-init containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc version: v1.1.12-0-g51d5e94 init version: de40ad0 Security Options: seccomp Profile: unconfined Kernel Version: 5.15.133.1-microsoft-standard-WSL2 Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 16 Total Memory: 15.19GiB Name: docker-desktop ID: e4ed03ab-df87-477b-8193-ce01571bc6c0 Docker Root Dir: /var/lib/docker Debug Mode: false HTTP Proxy: http.docker.internal:3128 HTTPS Proxy: http.docker.internal:3128 No Proxy: hubproxy.docker.internal Experimental: false Insecure Registries: hubproxy.docker.internal:5555 127.0.0.0/8 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support WARNING: No blkio throttle.write_bps_device support WARNING: No blkio throttle.read_iops_device support WARNING: No blkio throttle.write_iops_device support WARNING: daemon is not using the default seccomp profile

lbussell commented 9 months ago

[Triage] It would be good to know if this is a regression or not. Did this work for you using the .NET SDK 8.0.101? If you're not sure, can you try using this SDK image to run your build? mcr.microsoft.com/dotnet/sdk:8.0.101

That should tell us if there's an issue with .NET SDK 8.0.200 that released this week.

richlander commented 9 months ago

On my machine:

$ docker run --rm  mcr.microsoft.com/dotnet/sdk:8.0 cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
{
  "runtimeOptions": {
    "tfm": "net8.0"
  }
}

That suggests something else is at play.

Granock commented 9 months ago

when using FROM mcr.microsoft.com/dotnet/sdk:8.0.101 AS build for the build step the container builds.

But when running the container with FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base, i still get the error:

PS [pathToProject]> docker run 3be5fe
A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]

edited: a second error is, that the user app cant be found at runtime, for the container to build, i have to remove the USER app statement at the top

richlander commented 9 months ago

Can you try sdk:8.0 instead and see if that produces a different result?

The fact we are seeing a reference to 8.0.2 and you are using 8.0.101 suggests and incompatibility. Both last numbers should be ones or twos.

/cc @baronfel

Granock commented 9 months ago

I changed it to sdk:8.0 and got the same error as the one in the initial post:

PS [pathToProject]> docker build . -f .\CoreApi_Dockerfile -t core
[+] Building 0.6s (12/17)                                                                                                  docker:default
 => [internal] load build definition from CoreApi_Dockerfile                                                                         0.0s
 => => transferring dockerfile: 1.03kB                                                                                               0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0                                                                    0.2s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0                                                                 0.1s
 => [internal] load .dockerignore                                                                                                    0.0s
 => => transferring context: 464B                                                                                                    0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b246fc9a92feefe3aff49beb165fda4fc5a29122cd30768bafdc2d3e606c565c        0.0s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:789045ecae51d62d07877994d567eff4442b7bbd4121867898ee7bf00b7241ea      0.0s
 => [internal] load build context                                                                                                    0.0s
 => => transferring context: 5.36kB                                                                                                  0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                                  0.0s
 => CACHED [build 3/7] COPY [shared/., shared/.]                                                                                     0.0s
 => CACHED [build 4/7] COPY [core/., core/.]                                                                                         0.0s
 => CACHED [build 5/7] WORKDIR /src/core                                                                                             0.0s
 => ERROR [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"                                                      0.3s
------
 > [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj":
0.266 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
0.266 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
------
CoreApi_Dockerfile:20
--------------------
  18 |     WORKDIR /src/core
  19 |
  20 | >>> RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
  21 |     RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
  22 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147

View build details: docker-desktop://dashboard/build/default/default/ia9gfcsb4yit24szkwbqv1thv
richlander commented 9 months ago

Please do docker build --pull. You may get the same result, but it is required to correctly reason about your environment and its relationship to the current state of the tags in the registry.

Granock commented 9 months ago

trying with --pull:

PS [pathToProject]> docker build . --pull -f .\CoreApi_Dockerfile
[+] Building 0.5s (12/17)                                                                                                  docker:default
 => [internal] load build definition from CoreApi_Dockerfile                                                                         0.0s
 => => transferring dockerfile: 1.03kB                                                                                               0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0                                                                    0.1s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0                                                                 0.1s
 => [internal] load .dockerignore                                                                                                    0.0s
 => => transferring context: 464B                                                                                                    0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b246fc9a92feefe3aff49beb165fda4fc5a29122cd30768bafdc2d3e606c565c        0.0s
 => [internal] load build context                                                                                                    0.0s
 => => transferring context: 5.36kB                                                                                                  0.0s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:789045ecae51d62d07877994d567eff4442b7bbd4121867898ee7bf00b7241ea      0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                                  0.0s
 => CACHED [build 3/7] COPY [shared/., shared/.]                                                                                     0.0s
 => CACHED [build 4/7] COPY [core/., core/.]                                                                                         0.0s
 => CACHED [build 5/7] WORKDIR /src/core                                                                                             0.0s
 => ERROR [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"                                                      0.3s
------
 > [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj":
0.271 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
0.271 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
------
CoreApi_Dockerfile:20
--------------------
  18 |     WORKDIR /src/core
  19 |
  20 | >>> RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
  21 |     RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
  22 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147

View build details: docker-desktop://dashboard/build/default/default/j0nty6zk7jh38ai4a8a6q2obf

and with --no-cache:

PS [pathToProject]> docker build . --pull -f .\CoreApi_Dockerfile --no-cache
[+] Building 0.5s (14/17)                                                                                                  docker:default
 => [internal] load build definition from CoreApi_Dockerfile                                                                         0.0s
 => => transferring dockerfile: 1.03kB                                                                                               0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0                                                                    0.1s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0                                                                 0.1s
 => [internal] load .dockerignore                                                                                                    0.0s
 => => transferring context: 464B                                                                                                    0.0s
 => [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b246fc9a92feefe3aff49beb165fda4fc5a29122cd30768bafdc2d3e606c565c        0.0s
 => [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:789045ecae51d62d07877994d567eff4442b7bbd4121867898ee7bf00b7241ea      0.0s
 => [internal] load build context                                                                                                    0.0s
 => => transferring context: 5.36kB                                                                                                  0.0s
 => CACHED [build 2/7] WORKDIR /src                                                                                                  0.0s
 => CACHED [base 2/2] WORKDIR /app                                                                                                   0.0s
 => CACHED [final 1/2] WORKDIR /app                                                                                                  0.0s
 => [build 3/7] COPY [shared/., shared/.]                                                                                            0.0s
 => [build 4/7] COPY [core/., core/.]                                                                                                0.1s
 => [build 5/7] WORKDIR /src/core                                                                                                    0.0s
 => ERROR [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"                                                      0.2s
------
 > [build 6/7] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj":
0.204 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
0.204 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
------
CoreApi_Dockerfile:20
--------------------
  18 |     WORKDIR /src/core
  19 |
  20 | >>> RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
  21 |     RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
  22 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147

View build details: docker-desktop://dashboard/build/default/default/zs798eae30eestdb7tppv5hfi
richlander commented 9 months ago

Can you run this on your system?

docker run --rm  mcr.microsoft.com/dotnet/sdk:8.0 cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json

And add a RUN echo line that does the same thing just before that restore.

Granock commented 9 months ago

when running docker run --rm mcr.microsoft.com/dotnet/sdk:8.0 cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json

PS [pathToProject]> docker run --rm  mcr.microsoft.com/dotnet/sdk:8.0 cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
PS [pathToProject]>

as part of the docker file:

docker-file:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
#RUN apt-get update
#RUN apt-get install -y curl
#USER app
WORKDIR /app
EXPOSE 5000
EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

#Copy Shared-Projects
COPY ["shared/.", "shared/."]
#Copy CoreApi-Projects
COPY ["core/.", "core/."]
#Go To CoreApi-Directory
WORKDIR /src/core

RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
RUN cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Taubsi.CoreServer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Taubsi.Server.dll"]
HEALTHCHECK --interval=2m0s --timeout=10s --start-period=40s --start-interval=5s --retries=3 CMD [ "curl", "-f", "http://localhost:8080/HealthChecks"]

output:

PS [pathToProject]> docker build . --pull -f .\CoreApi_Dockerfile --no-cache --progress=plain
#0 building with "default" instance using docker driver

#1 [internal] load build definition from CoreApi_Dockerfile
#1 transferring dockerfile: 1.24kB done
#1 DONE 0.0s

#2 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0
#2 DONE 0.1s

#3 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0
#3 DONE 0.1s

#4 [internal] load .dockerignore
#4 transferring context: 464B done
#4 DONE 0.0s

#5 [build 1/9] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:b246fc9a92feefe3aff49beb165fda4fc5a29122cd30768bafdc2d3e606c565c
#5 DONE 0.0s

#6 [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0@sha256:789045ecae51d62d07877994d567eff4442b7bbd4121867898ee7bf00b7241ea
#6 DONE 0.0s

#7 [base 2/2] WORKDIR /app
#7 CACHED

#8 [build 2/9] WORKDIR /src
#8 CACHED

#9 [final 1/2] WORKDIR /app
#9 CACHED

#10 [internal] load build context
#10 transferring context: 5.36kB 0.0s done
#10 DONE 0.0s

#11 [build 3/9] COPY [shared/., shared/.]
#11 DONE 0.0s

#12 [build 4/9] COPY [core/., core/.]
#12 DONE 0.1s

#13 [build 5/9] WORKDIR /src/core
#13 DONE 0.1s

#14 [build 6/9] RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
#14 0.220 /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
#14 DONE 0.2s

#15 [build 7/9] RUN cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
#15 0.450
#15 DONE 0.5s

#16 [build 8/9] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
#16 0.472 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
#16 0.472 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
#16 ERROR: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147
------
 > [build 8/9] RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj":
0.472 A JSON parsing exception occurred in [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json], offset 0 (line 1, column 1): The document is empty.
0.472 Invalid framework config.json [/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json]
------
CoreApi_Dockerfile:22
--------------------
  20 |     RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
  21 |     RUN cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
  22 | >>> RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
  23 |     RUN dotnet build "./Taubsi.Server/Taubsi.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
  24 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"./Taubsi.Server/Taubsi.Server.csproj\"" did not complete successfully: exit code: 147

View build details: docker-desktop://dashboard/build/default/default/1n9o5pxpx3qqytkhb545tbpzp
richlander commented 9 months ago

Can you share your PackageReferences? I'm wondering if something if deleting that file.

You could run your build as non-root to with USER app to see if we get a different error.

Apologies on echo. Yes, I meant cat.

Granock commented 9 months ago

When i try running the build as user app:

#13 [build 5/9] WORKDIR /src/core
#13 DONE 0.1s

#14 [build 6/9] RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
#14 ERROR: process "/bin/sh -c echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json" did not complete successfully: unable to find user app: no matching entries in passwd file
------
 > [build 6/9] RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json:
------
CoreApi_Dockerfile:21
--------------------
  19 |     WORKDIR /src/core
  20 |
  21 | >>> RUN echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
  22 |     RUN cat /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json
  23 |     RUN dotnet restore "./Taubsi.Server/Taubsi.Server.csproj"
--------------------
ERROR: failed to solve: process "/bin/sh -c echo /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.2/Microsoft.NETCore.App.runtimeconfig.json" did not complete successfully: unable to find user app: no matching entries in passwd file

View build details: docker-desktop://dashboard/build/default/default/fi03stahoktq6mjvb5k3e9gnw

for the PackageReferences:


Taubsi.Server
-> Swashbuckle.AspNetCore at 6.4.0
->Taubsi.Service
---> CommunityToolkit.Diagnostics at 8.2.2
---> Taubsi.Model
-----> Microsoft.EntityFrameworkCore at 8.0.1
-----> Microsoft.EntityFrameworkCore.InMemory at 8.0.1
-----> Microsoft.EntityFrameworkCore.Sqlite at 8.0.1
-----> Microsoft.EntityFrameworkCore.Tools at 8.0.1
------> with <PrivateAssets>all</PrivateAssets> &<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
-----> Npgsql.EntityFrameworkCore.PostgreSQL at 8.0.0

-> Taubsi.Configuration
---> Microsoft.Extensions.Diagnostics.HealthChecks at 8.0.1
---> Microsoft.Extensions.Hosting at 8.0.0
---> Serilog.Extensions.Hosting at 8.0.0
---> Serilog.Formatting.Compact at 2.0.0
---> Serilog.Sinks.Async at 1.5.0
---> Serilog.Sinks.Console at 5.0.1
---> Serilog.Sinks.File at 5.0.0
---> Taubsi.Model (same as above)
---> Microsoft.AspNetCore.App (Framework Reference)
richlander commented 9 months ago

That's very odd.

I assume you added USER app above those RUN lines.

Does the following work on your machine?

docker run --rm -u app mcr.microsoft.com/dotnet/sdk:8.0 whoami
app

Please delete the RUN echo line. It's not actually doing anything useful and I have no idea why it is failing. We want the RUN cat line.

Granock commented 9 months ago

user doesnt seem to exist

PS [pathToProject]> docker run --rm -u app mcr.microsoft.com/dotnet/sdk:8.0 whoami app
docker: Error response from daemon: unable to find user app: no matching entries in passwd file.
Granock commented 9 months ago

Tried it with the 8.0.101 version, that works

PS [pathToProject]> docker run --rm -u app mcr.microsoft.com/dotnet/sdk:8.0.101 whoami
app
PS [pathToProject]> docker run --rm -u app mcr.microsoft.com/dotnet/sdk:8.0 whoami
docker: Error response from daemon: unable to find user app: no matching entries in passwd file.
PS [pathToProject]>
Granock commented 9 months ago

i did a check an tried to run the commands and the build on another machine. There they succeed and the build is successfull. for the whoami i am getting app, and the json file that the error complains about has some content.

So it seems the problem only happens on my primary machine.

richlander commented 9 months ago

Ya. Something is wrong with your system. Can you reboot?

Granock commented 9 months ago

Reboots didnt help. I

trying it now, the image works and everything runs as expected.

ignacy130 commented 6 months ago

I have similar problem on mcr.microsoft.com/dotnet/sdk:8.0 even though I've reinstalled docker and rebooted a few times recently. It started to appear after a day, was working initially.

I can't even RUN dotnet --version on this image but I can on mcr.microsoft.com/dotnet/sdk:8.0-alpine and mcr.microsoft.com/dotnet/sdk:8.0.101 so thanks for the tips! The error is:

 => ERROR [build-env 4/5] RUN dotnet restore                                                                                                                                                                                                                                 0.2s 
------
 > [build-env 4/5] RUN dotnet restore:
0.212 exec /bin/sh: exec format error
------
Dockerfile:7
--------------------
   5 |     COPY . ./
   6 |     # Restore as distinct layers
   7 | >>> RUN dotnet restore
   8 |     # Build and publish a release
   9 |     RUN dotnet publish -c Release -o out
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore" did not complete successfully: exit code: 1

Should I post it as another bug?

lbussell commented 6 months ago

Should I post it as another bug?

@ignacy130 Yes, please open another issue and I'll be happy to investigate - https://github.com/dotnet/dotnet-docker/issues/new/choose