Sample .NET Core Docker file

Here is a working example of a simple Docker file for a .NET Core 3.1 project

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

COPY project.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/runtime:3.1

WORKDIR /app
COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "project.dll"]

Docker cribsheet

Build

Build an image from the Dockerfile in the current directory and tag the image

docker build -t myimage -f Dockerfile .

List all images that are locally stored with the Docker Engine

docker ps -a

Delete an image from the local image store

docker image rm CONTAINER_NAME

You may want to remove all orphaned images, you can do this with dandling field

docker rmi $(docker images -f dangling=true -q)
Continue reading Docker cribsheet →

this and that