DEV Community

wk
wk

Posted on

Create small ASP.NET Core Docker

  • Create project
$ dotnet new webapi --language F# --output src/MyWeb
  • Create Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:5.0-alpine AS base

WORKDIR /app
COPY src/MyWeb/MyWeb.fsproj src/MyWeb/
RUN dotnet restore src/MyWeb

COPY src/MyWeb src/MyWeb
RUN dotnet publish src/MyWeb \
    -r linux-musl-x64 \
    -c Release \
    -o /out \
    -p:PublishTrimmed=true

FROM mcr.microsoft.com/dotnet/core/runtime-deps:5.0-alpine
WORKDIR /app
COPY --from=base /out ./
CMD ./MyWeb
EXPOSE 80
  • Build image
$ docker build -f Dockerfile  -t wk/my-web .
  • Check image size
$ docker images | grep wk/my-web
wk/my-web    latest     e03dd2b6b198    4 hours ago    72.4MB

Top comments (0)