Open kurt-mueller-osumc opened 10 months ago
See this post: https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/
There are two options:
$BUILDPLATFORM
)@richlander Rosetta emulation doesn't work. After a long wait, it's shutdown with that:
assertion failed [block != nullptr]: BasicBlock requested for unrecognized address
(BuilderBase.h:550 block_for_offset)
and exit code: 133
Did you consider the $BUILDPLATFORM
approach?
@richlander That's works fine. But Rosetta's behaviour is very strange here.
Got it. Let's transfer this issue to dotnet/runtime.
Hey @richlander, thanks for the link to that post. I'll read it and try to adopt my approach to utilize best practices.
For me, the problem is that official microsoft images like https://hub.docker.com/_/microsoft-azure-functions-dotnet-isolated are linux/amd64 only... and the only way I know how to get this docker image working on my M1 Macbook is using rosetta emulation.
But then that causes dotnet restore
to hang indefinitely unless I set the following environment variable to false:
ENV DOTNET_EnableWriteXorExecute=0
[Triage] This doesn't seem like .NET setup issue. @richlander do you have a suggestion for who should take a look?
Did you guys got it work. I am having similar problem.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
WORKDIR /source
COPY certs/. /usr/local/share/ca-certificates/
RUN update-ca-certificates
# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -a $TARGETARCH
# copy and publish app and libraries
COPY . .
RUN dotnet publish --no-restore -a $TARGETARCH -o /app
# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
WORKDIR /app
COPY --from=build /app .
COPY certs/. /usr/local/share/ca-certificates/
RUN apk --no-cache add ca-certificates && \
update-ca-certificates
# Uncomment to enable non-root user
# USER $APP_UID
ENTRYPOINT ["./PropertyStandardsAPI"]
I build it using buildctl/buildkit It is stuck on restore
#9 [internal] load build context
#9 transferring context: 36.64kB 0.0s done
#9 DONE 0.3s
#11 [build 3/8] COPY certs/. /usr/local/share/ca-certificates/
#11 CACHED
#12 [build 4/8] RUN update-ca-certificates
#12 CACHED
#13 [build 5/8] COPY *.csproj .
#13 CACHED
#14 [build 6/8] RUN dotnet restore -a amd64
#14 2.956 Determining projects to restore...
It runs fine locally on Ubuntu machine, but not in Redhat machine (Red Hat Enterprise Linux release 8.2 (Ootpa))
I just tried our sample w/o issue on macOS Arm64 w/Rosetta emulation enabled.
I used --platform linux/amd64
as it appears you did, too.
Can you share a project file so that I can test that? Are you reliant on any authorized feeds?
I appear to have the same issue..
M1 Sonoma 14.3.1 Docker 4.27.2 (with rosetta enabled)
When I download the dotnet binaries (x64) and execute them (without docker and with rosetta) they run without issue. Given this I guess this is some kind of docker + rosetta issue.
I just tried our sample w/o issue on macOS Arm64 w/Rosetta emulation enabled.
I used
--platform linux/amd64
as it appears you did, too.Can you share a project file so that I can test that? Are you reliant on any authorized feeds?
@richlander I have a simple project here that fails when running dotnet restore
:
hangs for me too on M2
Finally! I was able to fix this restore issue.
Macbook Pro M1 Pro chip Sonoma 14.3.1 Docker 4.28.0 (139021) ✅ Use Rosetta for x86_64/amd64 emulation on Apple Silicon
I tried to build my docker image initially in default platform, it stuck in dotnet restore
step but I need to build in linux/amd64 because Azure resource that I use to run my container doesn't support linux/arm64. Then I tried to build it in linux/amd64 but still dotnet restore
was stuck. Then after reading multiple issues I've tried adding ENV DOTNET_EnableWriteXorExecute=0
and that fixed the issue.
And here is my final Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build-env
ENV DOTNET_EnableWriteXorExecute=0 #Needed to add this line
WORKDIR /src
COPY *.csproj .
RUN dotnet restore CommandsService.csproj
COPY . ./
# Build and publish a release
RUN dotnet publish -c Release -o output
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /src/output .
ENTRYPOINT ["dotnet", "CommandsService.dll"]
I didn't specify --platform because I've set DOCKER_DEFAULT_PLATFORM=linux/amd64
environment variable on my mac with M1 Pro chip.
But it seems wether you are building in linux/amd64
or default linux/arm64
you must set ENV DOTNET_EnableWriteXorExecute=0
on your Dockerfile to be able to restore. It took 3-4 minutes on my case to restore so you need to be patient.
It should go much faster if you follow this pattern.
https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile
https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/
A potential workaround is to remove the --platform
flag and specify the runtime specifically, as others have found sucess with in this thread: https://github.com/dotnet/dotnet-docker/issues/4225
This has been an ongoing issue unfortunately... And none of the answers to the dozens and dozens of github issues for this topic (Or the blog post) seem to work for any of my coworkers on Apple silicon (Who have been affected for nearly a year now)
This specific comment is our guidance: https://github.com/dotnet/dotnet-docker/issues/4225#issuecomment-1733815253
Sorry. I misread what you said. Too much in a rush.
Can you tell me more about your workaround?
I had the same problem this solved my problem Dockerfile:
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /app
COPY *.csproj ./
ENV DOTNET_NUGET_SIGNATURE_VERIFICATION=false
RUN dotnet restore -a $TARGETARCH
COPY . .
RUN dotnet publish -c Release -o out -a $TARGETARCH
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
EXPOSE 5241
ENTRYPOINT ["dotnet", "AuthAPI.dll"]
To get a build you can just use the --platform argument in docker build. To build an image for linux/amd64 just use the following build command:
docker build --platform linux/amd64 .
Had the same problem few moths ago, and I managed get it working just with
docker build --platform linux/amd64 .
For some reason today it refused to work Adding DOTNET_EnableWriteXorExecute=0 solved the issue
Dotnet docker building is totally broken on my m2 mac, I don't know what's going on. I have tried the solutions listed above, but nothing works.
docker system prune --all --force
mkdir docker-test && cd docker-test
curl https://raw.githubusercontent.com/dotnet/dotnet-docker/main/samples/aspnetapp/Dockerfile -o Dockerfile
new webapp -n aspnetapp
docker build --platform linux/amd64 -t app .
And it just hangs forever....
=> [build 3/6] COPY aspnetapp/*.csproj . 0.0s
=> [build 4/6] RUN dotnet restore -a amd64 98.6s
=> => # Determining projects to restore...
=> [stage-1 2/3] WORKDIR /app 0.1s
~/src/docker-test❯uname -a
Darwin CNHI-KTY020666V-macOS 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020 arm64
Describe the Bug
Similar to https://github.com/dotnet/dotnet-docker/issues/3338 and https://github.com/dotnet/runtime/issues/71856, trying to emulate the
linux/amd64
platform when building a docker image on an arm64 computer (i.e. Macbook) cause the build to hang when thedotnet restore
command is ran.Steps to Reproduce
docker build --platform linux/amd64 .
This project source code is simply the default library template for the F# language.
Other Information
Output of
docker version
Output of
docker info