All Fixes With Docker On Apple M1/M2/M3 Pro

Docker Dolphin on Apple Silicon Chip for Non ARM Images

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

Expected Output

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:

1. Check the box for Rosetta Option for x86_64

2. Set file sharing with VirtioFS and apply as per your need
3. Set proper resource as per keeping good performance
4. Set registry-mirrors in case if you are working for some organisation artifactory

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://github.com/rancher-sandbox/rancher-desktop/releases/download/v1.7.0/Rancher.Desktop-1.7.0.aarch64.dmg

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.

colima start -c 4 -m 8 -d 64 --network-access

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

Expected Output

% docker image inspect nginx:1.8 -f ‘{{ .Architecture }}’

amd64

Docker Container for nginx image
Output
Docker container is working fine with amd64 image on Apple Silicon Chip

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

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.

list all the docker services
To check the detail error message for the service

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.

Now, the unsupported platform error is gone.

Docker stack is working fine with amd64 image on Apple Silicon Chip

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.

share or like this post
Share

Leave a Reply

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

Share