x64 is no longer the only relevant architecture. Apple switched to ARM with the M1 chip, and Microsoft is pushing ARM as well. If you want to run your application on both ARM64 and x64, you need a Docker image for each architecture. Docker supports multi-arch images, which let you publish a single image tag that works across multiple architectures.
To create a multi-arch Docker image, you build a separate image for each architecture and then create a manifest that references them. The Docker client uses this manifest to pull the correct image for the current architecture. Here are the tags you need to create:
mysampleapp:1.0.0-x64 which will be the image for x64 architecturemysampleapp:1.0.0-arm64 which will be the image for ARM64 architecturemysampleapp:1.0.0 which will be the manifest that references the previous images
To create the images, use the dotnet publish command with a few properties to configure the image. This is simpler than writing a Dockerfile and builds faster.
PowerShell
# Create a new web project
dotnet new web
PowerShell
# Create 2 images for x64 and ARM64
$registry = "ghcr.io"
$image = "meziantou/mysampleapp"
$tag = "latest"
dotnet publish -p:PublishProfile=DefaultContainer --configuration Release --os linux --arch x64 -p:ContainerImageTag=$tag-x64 -p:ContainerRepository=$image -p:ContainerRegistry=$registry
dotnet publish -p:PublishProfile=DefaultContainer --configuration Release --os linux --arch arm64 -p:ContainerImageTag=$tag-arm64 -p:ContainerRepository=$image -p:ContainerRegistry=$registry
Then combine the images into a manifest and push it to the registry:
PowerShell
docker manifest create "$registry/${image}:$tag" "$registry/${image}:$tag-x64" "$registry/${image}:$tag-arm64"
docker manifest push "$registry/${image}:$tag"
#Additional resources
Do you have a question or a suggestion about this post? Contact me!