I have published my console app using this command:
dotnet publish -c Release --self-contained.
I have created a dockerfile inside the project folder and this is the content of that:
FROM scratch
COPY bin/Release/net7.0/win-x64/publish .
ENTRYPOINT ["JustForDocker.dll"]
docker build -t dockername .
A self-contained .NET app isn't going to work in a scratch
container without more native dependencies. It's only self-contained in terms of .NET runtime. But the .NET runtime still depends on native libraries such as OpenSSL. Instead, you'll want to make use of the official runtime-deps
container images produced for .NET: https://github.com/dotnet/dotnet-docker/blob/main/README.runtime-deps.md.
So if you change FROM scratch
to FROM mcr.microsoft.com/dotnet/runtime-deps:7.0
, that should give you what you're after.