DEV Community

wk
wk

Posted on

4 1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay