.NET docker image amd64 building on M1

docker ကို macbook m1 မှာသုံးတာ သူဟာသူ M1 မှာ docker image build ပြီး container run တာက ကောင်းကောင်းအလုပ်လုပ်ပေမယ့် image support type က arm ဆိုတော့ အဲ image ကို aws ECS or azure AKS မှာတင်သုံးတဲ့အခါမှ Linux OS ဆိုတော့ docker image က အလုပ်မလုပ်ဘူးဖြစ် ဒါနဲ့ amd64 support image M1 ကနေ ဘယ်လို build လည်းရှာကြည့်ပြီးလုပ်ကြည့်ဖြစ်တယ်

docker build --platform linux/amd64 -t fidoapi:v1 .

ဒီ command သုံးပြီ build ပေမယ် image building မှာ dotnet restore နေရာမှာ stuck ဖြစ်ဖြစ်နေ မိနစ် ၂၀ လောက်ထိကို ကြာ ဘာမှ ဆက်မဖြစ် ၂ရက်လောက် အတော်ရှာလိုက်ရတယ် အဲဒါက docker file မှာ run time က default သုံးထားရင် OS နဲ့ compatible ဖြစ်တာနဲ့ပဲဆိုတော့ arm64 နဲ့ပဲ သွား build နေတာ command မှာက –platform linux/amd64 ဆိုတော့ တိုင်တွေပတ်ကုန်တာ

# Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:7.0
WORKDIR /app
COPY --from=build-env /app/out .
CMD ASPNETCORE_URLS=http://*:$PORT dotnet fidoapi.dll

ဒီမှာသုံးထားတဲ့ run time က
mcr.microsoft.com/dotnet/runtime:7.0 အလုပ်က project တခုမှာ ကြုံဖူးတာသွားသတိရပြီး run time ပြောင်းရမယ်ဆိုပေမယ့် .NET 7 တွက်ဟာ ရှာမရဖြစ်နေတာ ကံကောင်းစွာနဲ့သွားတွေ့လို့ mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-amd64 သုံးလိုက်တော့မှာ linux/amd64 OS support တဲ့ docker image build success ဖြစ်သွားတော့တယ်

# Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-amd64
WORKDIR /app
COPY --from=build-env /app/out .
CMD ASPNETCORE_URLS=http://*:$PORT dotnet fidoapi.dll

Leave a Reply

Your email address will not be published. Required fields are marked *