Table of Contents

Docker

Installation

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Enable cross-build with qemu

docker run --privileged --rm tonistiigi/binfmt --install all
Tip

This command would register qemu to kernal, it needs root privilege and run every time restart the system

The Dockerfile should use --platform <arch> for build image selection.

Example:

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Here we need add the build platform
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY . .
RUN dotnet restore "Backend/Backend.csproj"
COPY . .
WORKDIR "/src/Backend"
RUN dotnet build "./Backend.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Backend.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Backend.dll"]

Clean up all data

docker system prune -a
docker buildx prune -a
docker volume prune -a
Caution

This command would remove all unused data, including images, containers, volumes, and networks. Use with caution.

Trust self-signed certificate

{
  "insecure-registries": [
    "myregistry.local:5000"
  ]
}

Reference

Docker Doc