# Creates a simple .Net console application, writing second-tick counts to the terminal # build with: docker build -t REP/IMAGE_NAME:TAG . # run with: docker run --rm -it IMAGE_NAME # list intermediate imgs: docker images --filter label=stage=builder FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder LABEL stage=builder WORKDIR /app # Copy everything from src-directory on host to workdir in image COPY src . # Build and publish a release to directory "out" (build implicitly restores NuGet packages) RUN dotnet publish -c Release -o out # uncomment for testing the build-env image # CMD ["dotnet", "bin/Release/net7.0/DotnetDocker-01.dll"] # Build runtime image # FROM mcr.microsoft.com/dotnet/aspnet:7.0 FROM mcr.microsoft.com/dotnet/runtime:7.0 # create user in the image RUN groupadd -r mygroup && useradd --no-log-init --create-home --shell /bin/bash -r -g mygroup myuser # change user USER myuser # make app-dir (WORKDIR cmd would create a dir owned by root -> permission denied!) RUN mkdir /home/myuser/app # set build- and run-time working directory WORKDIR /home/myuser/app COPY --chown=myuser:mygroup --from=builder /app/out . # Opt-out of the diagnostic pipeline. This allows the container to run as read-only. ENV COMPlus_EnableDiagnostics=0 # # CMD ["dotnet", "ASYD_Demo.dll"] ENTRYPOINT ["dotnet", "ASYD_Demo.dll"]