I have following DockerFile
and trying to build this image on my MacBook with M1 Max chip:
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["src/MyProject/MyProject.csproj", "src/MyProject/"]
RUN dotnet restore "src/MyProject/MyProject.csproj"
COPY . .
WORKDIR "/src/src/MyProject"
RUN dotnet build "MyProject.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProject.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
ENTRYPOINT ["dotnet", "MyProject.dll"]
For building the image I tried this command:
docker buildx build --platform linux/amd64 -t myproject:latest --load -f src/MyProject/Dockerfile .
I test architecture after build like this:
docker inspect --format '{{.Os}}/{{.Architecture}}' myproject:latest
I got linux/amd64
When I tried to run this image on my server, I got following error and application is not running:
standard_init_linux.go:228: exec user process caused: exec format error
What I tried also:
- Clean old local images
- Check what architecture is on server with command
uname -m
and I getx86_64
.