Search code examples
dockerazure-aksapple-m1

build docker image in M1 to deploy in aks cluster


I am trying to deploy the following docker image in my M1:

FROM node:14

WORKDIR /usr/src/app

COPY package.json .
COPY package-lock.json .

RUN npm install --production

COPY index.js .

CMD ["node", "index.js"]

now when I try to deploy the image in azure aks cluster using the following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-hello-world
  namespace: "default"
  labels:
    app: node-hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: node-hello-world
  template:
    metadata:
      labels:
        app: node-hello-world
    spec:
      containers:
        - name: node-hello-world
          image: acrappstrodev.azurecr.io/node-hello-world:v1
          ports:
            - containerPort: 3000

I am getting a CrashLoopBackOff error.

Drilling down on the issue more I saw something like building an image in M1 which is an ARM based system on AKS cluster which is of architecture x86_64 is incompatible.

If this is the case how do I build an image for AKS cluster from my mac m1?


Solution

  • How to build locally with Docker and Buildx

    If this is the case how do I build an image for AKS cluster from my mac m1?

    https://docs.docker.com/build/building/multi-platform/

    From command line, with a new enough version of Docker, you can build a Docker image for a different platform architecture (like x86_64 on your aarch64 platform) with buildx command and --platform linux/amd64 flag:

    docker buildx build --platform linux/amd64 -t <YOUR IMAGE TAG> .
    

    This will build an image that can run on a cluster that runs architecture x86_64 images. You should be able to push the tag to your Azure Container Repository to then run on AKS.