Created
June 15, 2023 13:05
-
-
Save ptupitsyn/1c0f4d6186f63c0f09689745242ebee5 to your computer and use it in GitHub Desktop.
Working .NET multi-arch Docker build (ARM + Intel)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
docker buildx build --platform linux/amd64,linux/arm64 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/ | |
# 8.0-preview-alpine works too | |
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build | |
ARG TARGETARCH | |
WORKDIR /source | |
# copy csproj and restore as distinct layers | |
COPY *.csproj . | |
RUN dotnet restore -a $TARGETARCH | |
# copy everything else and build app | |
COPY . . | |
RUN dotnet publish -a $TARGETARCH --no-restore -o /app | |
# final stage/image | |
FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview | |
# Needed when csproj is .NET 7 | |
ENV DOTNET_ROLL_FORWARD=Major | |
ENV DOTNET_ROLL_FORWARD_PRE_RELEASE=1 | |
WORKDIR /app | |
COPY --from=build /app . | |
USER $APP_UID | |
ENTRYPOINT ["./dotnet-arm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<!-- We use SDK 8 to build, but the project can use .NET 7 or 6. --> | |
<TargetFramework>net7.0</TargetFramework> | |
<RootNamespace>dotnet_arm</RootNamespace> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine("Hello, World!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment