NextJS Build Issues with Mac M1 and Docker Desktop
While developing a NextJS web application with Mac M1 and docker desktop, I faced a number of issues. This article summarises the problems and how I solved it.
The first issue I faced was during the docker container build from the NextJS folder with a Dockerfile. I used the following command to build the container image,
During the docker build, the following error was observed when RUN npm install task was running,
=> => # #
=> => # # Fatal process OOM in Failed to reserve virtual memory for CodeRange
=> => # #
=> => # qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
It turned out that this is an issue with Mac M1 machines if you are using older versions of docker desktop. Upgrading docker desktop to 4.5 solved the issue!
The next issue I faced was when I tried to deploy the docker image on an Azure AKS cluster running Linux VMS. The container failed to load on AKS with the CrashLoopBackOff error. The interesting thing was that this container image ran without any issues on my local Mac M1. I ran the following kubectl command to find the root cause of this error in AKS,
The above command showed the following error text,
Then I realised that Mac M1 is generating container images suitable for ARM architecture! So to force creation of a docker images suitable for linux, I used the following modified command to create docker images,
This solved the issue and my NextJS app was running without any issues on AKS cluster.