Introduction
The majority of existing Docker images support x86_64, and this poses a problem for the ARM ecosystem. Support for ARM has started to pick up – but there’s still much to be done before it goes mainstream. I recently bought Apple M2 Max and had lots of different issues to run docker container in effective way. I decided to share my journey here.
Issues faced on Silicon Chip
- By default the ARM images are supported on Apple Silicon Chip
- Performance Issue with Non ARM platform images
- Running a docker stack with Non ARM Images
I will address all above issue faced on Apple Silicon. Lets start from scratch to setting up our environment with can address all above issues.
Install Rosetta
Run following command to install rosetta on Apple Silicon Mac
1 |
softwareupdate --install-rosetta --agree-to-license |
Expected Output
1 2 3 4 5 6 |
% softwareupdate --install-rosetta --agree-to-license By using the agreetolicense option, you are agreeing that you have run this tool with the license only option and have read and agreed to the terms. If you do not agree, press CTRL-C and cancel this process immediately. 2023-03-04 12:51:11.903 softwareupdate[1463:36671] Package Authoring Error: 032-48321: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute Install of Rosetta 2 finished successfully |
Setting default platform for docker
By default docker picks up the device architecture platform to pull the docker image. As many images does not built for ARM platform, therefore it’s an issue and big impediment for your current project where only you have Apple Silicon Chip laptop. In general, most of the images built for x86_64 and amd64, therefore the solution of this issue is set explicit default docker platform on Apple Silicon Chip Mac M1/M2 Pro/Max.
echo 'export DOCKER_DEFAULT_PLATFORM=linux/amd64' >> ~/.zshrc
source ~/.zshrc
Different Options to have Docker on Mac
- Docker Desktop
- Racher Desktop
- Colima
There are many ways to run docker on Mac, but I am only explaining three.
Install Docker Desktop
As most of us knows that Docker Desktop is not free any more for all, therefore please check with your organisation before using it. But as personal level you can use free of cost and even if you are freelancer as well. The official documentation is following:
https://docs.docker.com/desktop/install/mac-install/
Optimise Docker Desktop for docker performance
To have better docker experience with docker desktop. Apply following settings:
Based on above setting we are all set with Docker Desktop settings.
Install rancher desktop
Rancher desktop is a free alternative to docker desktop. Follow below
https://docs.rancherdesktop.io/getting-started/installation/
Install Colima for docker
Colima is the third alternative to run docker using QEMU VM, that can be created for different platform.
1 |
brew install colima |
colima start -c 4 -m 8 -d 64 --network-access
1 |
colima list |
Lets run an Image built for linux/amd64
To demonstration this setup working, I chose nginx:1.8 image which is only built for linux/amd64
1 2 3 |
docker pull nginx:1.8 docker image inspect nginx:1.8 -f '{{ .Archirecture }}' |
Expected Output
% docker image inspect nginx:1.8 -f ‘{{ .Architecture }}’
amd64
Docker Container for nginx image
1 |
docker run -d -p 8080:80 nginx:1.8 |
Output
Deploy Docker stack with Non ARM platform image
To deploy docker stack we require a docker compose file. Need to activate the swarm mode as well.
To activate docker swarm, run below command
docker swarm init
Lets create one for nginx. create nginx.yml
1 2 3 4 5 6 7 |
version: "3.9" services: nginxservice: image: nginx:1.8 ports: - 8080:80 |
1 2 |
docker stack deploy -c nginx.yml nginxstack |
Output
Verify now if nginx service is up and running
In above screenshot, as shown we have got error for “no suitable node”. To check the complete error code. Run below command.
1 |
docker service ls |
As error says, “unsupported platform”. “docker stack” expect only ARM images. Therefore, it does some verification. To address this issue, need to remove the current stack and add “–resolve-image never” while deploying any stack.
1 2 3 |
docker stack rm nginxstack docker stack deploy -c nginx.yml --resolve-image never nginxstack |
Now, the unsupported platform error is gone.
Conclusion
Finally, you have made it till here that means you enjoyed the article. I hope that it provides some solution for your issues. Now, all the non-ARM images are working perfect on ARM platform of Apple Silicon Chip. Happy dockerisation.