avatarStringMeteor

Summary

Docker now supports running x86 containers on Apple Silicon Macs through Rosetta 2, offering better performance and compatibility over previous methods.

Abstract

The article discusses the recent enhancement in Docker that allows users to run x86-based container images on Apple Silicon Macs by leveraging the Rosetta 2 translator. This development supersedes the previous requirement to use QEMU emulation, which was less efficient and prone to compatibility issues. Users need to update to the latest version of Docker Desktop and enable the virtualization framework and Rosetta emulation in the app settings. The feature simplifies the transition to Apple Silicon Macs and provides a smoother experience for running x86 containers.

Opinions

  • The author emphasizes the ease of using Rosetta 2 support in Docker Desktop, which eliminates the need for additional setup or configuration.
  • Performance improvements and better compatibility when running x86 containers through Rosetta 2 compared to QEMU are noted by the author.
  • Despite being listed as in development, the author has not encountered any issues with the x86 container images tried.
  • The author suggests that the Rosetta 2 feature in Docker is a significant step forward, facilitating the adoption of ARM-based Macs.
  • The author recommends Kubernetes kind for running a Kubernetes cluster on Apple Silicon Macs.
  • The author offers further reading on related topics and encourages readers to join Medium through a referral link to access more content.

Docker

Docker on Apple Silicon Mac: How to Run x86 Containers with Rosetta 2

Running x86 containers on Apple Silicon Macs just got easier thanks to newly added Docker’s Rosetta support. Discover how to use it in this guide.

Photo by Venti Views on Unsplash

Finally, the popular containerization platform Docker has implemented a new feature that allows running images built for the x86 architecture on Macs utilizing the Apple Rosetta 2 emulator/translator.

This means that users can now run their pre-existing x86-based Docker images on Macs featuring Apple Silicon processors without the need for rebuilding them or utilizing QEMU emulation.

Prior to this feature, the only option for running x86-based Docker images on Macs with Apple Silicon processors was through QEMU emulation, which could often result in compatibility issues and runtime crashes with particular images. However, with the integration of Rosetta 2 support, users can now expect a smoother experience when running their x86-based Docker images on Apple Silicon Mac systems.

Not only is the new Rosetta 2 feature built directly into the operating system, but it also eliminates the need for additional setup or configuration, making it even more user-friendly. Additionally, as Rosetta 2 is specifically designed by Apple for the macOS operating system and thanks to the optimizations Apple has integrated into its Apple Silicon CPUs, it is expected to provide improved performance and compatibility compared to QEMU emulation.

How to enable Rosetta 2 virtualization feature in Docker Desktop

To enable the new Rosetta virtualization feature in Docker, first make sure you have updated to the latest version of the Docker Desktop app. Go to the Software updates section in the app settings and install any available updates. At the time of writing this story, the latest version was 4.16.1.

Updates section in the Docker Desktop app — Image by author

Next, go to the General section and check the box to enable the Apple Virtualization framework.

Enable Virtualization framework in the Docker Desktop app — Image by author

Finally, in the Feature in development section, enable Rosetta.

Enable Rosetta emulation in the Docker Desktop app — Image by author

After changing these settings, the Docker Desktop app may restart before becoming available again.

That’s it. You’re ready to go.

I’ve received reports in which some users couldn’t see the “Use Rosetta option in the “Features in development section. That’s because sometimes Docker must be updated multiple times until the latest version is reached, and it cannot be updated directly to the latest version but must pass through the intermediate ones first. So, please make sure you have installed version 4.16 or later when updating.

Run x86 containers with Rosetta

If you want to build and run x86 container images using Rosetta, use the platform flag as in the following commands:

docker build --platform linux/amd64 -t my_container_image .

docker run --platform linux/amd64 my_container_image
Commands to build and run Docker x86 containers — Image by author

Notice how you could use the same commands even without having enabled the Virtualization framework and Rosetta emulation. In that case the containers would be run through the QEMU emulator.

Conclusion

The inclusion of Rosetta 2 support in Docker for Mac is a major advancement that allows for a more seamless and efficient experience when running x86-based Docker images on Macs with Apple Silicon processors, and will help smooth out the transition to new ARM Macs.

On a side not, even though the feature is still listed as in development I haven’t personally noticed any issues with the container images I’ve tried.

Let me know in the comments whether you’ve noticed performance improvements when running your x86 container through the Rosetta emulation compared to QEMU, or if you’ve encountered issues with it.

Then, if you’re curious about deploying your containers in Kubernetes, I’d recommend checking out kind. It’s a really handy tool that lets you run an entire K8s cluster within a single Docker container. Yes, that is running containers inside containers:

I actually wrote this story about it, detailing how I use it to run both ARM and x86 containers simultaneously with the help of Rosetta 2, and shared some useful tips.

Further reading

If you liked 👏 this article you may enjoy reading through some of my other articles. Oh, and don’t forget to follow me! 🫵

Consider becoming a Medium member through my referral link if you appreciate reading stories from me. You get a 1-month free trial that gives you unlimited access to all Medium content. 🎁

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job

Technology
Apple
Mac
Docker
Programming
Recommended from ReadMedium