PSA: Enable Rosetta In Your Docker Settings

A trend I’ve noticed since entering the developer workforce mid-2022: many of my peers love coding on a Macbook. And why wouldn’t they?It’s simple to set up a dev environment. And, considering that most packages and package managers present themselves as almost tailor-made for the Mac — which, arguably, is a benefit of macOS being Unix-based — it’s almost a no-brainer. With that said, I’m not attempting to convince you to ditch your Windows machine for coding.

I am here to bring to your attention a certain setting within a very popular virtualization software, Docker. We’ll discuss why and how you can enable Rosetta in your Docker settings.

What Is Docker?

For those of you who don’t know, Docker is software that allows you to set up containers that can effectively run virtual machines on your computer. From mock databases to entire servers, Docker makes it easy to test your creations in an environment exclusive of your machine’s operating system. It’s quite nifty.

On many of my projects — past and current — Docker enabled me to launch many different databases and servers that behaved as if they were the real, intended environments. The value it has brought to me is sky-high. My teammates and I have managed to resolve and anticipate most bugs and behaviors since we have a solid idea of what our project should expect. The containers can attach themselves to your computer as if it were on your local network, so you can send and receive data through other applications such as Postman.

The issue with Docker begins when you’re attempting to run an x86-based container on a Mac that does not operate on an Intel chip.

Why Is That An Issue?

Macbooks possess many different CPU options, but they’re part of two main groups: Intel and Apple.

The Intel chips are built on the same architecture as most other existing CPUs you can find within your typical PC, that being x86_64. This doesn’t pose a problem when trying to run x86 docker containers — the instructions sent to the CPU are perfectly readable. Pretty much all Apple products manufactured before 2020 are running on this CPU.

Apple CPUs are built on an Arm64 architecture and can be found in the M1, M2, M3, and their Max variants. This architecture processes its instructions differently than the x86-based chips. Herein lies the problem. Because the Mx series chips are unable to process the x86 instructions, it’s now impossible to use any x86-based applications with a Mac running on this CPU.

Is This Where Rosetta Comes In?

Simply put: Yes.

Apple originally developed and released Rosetta in 2006 when they switched processor types from PowerPC to Intel. Rosetta is an emulation software that behaves as an interface layer between the software on your Mac and the hardware that runs it. Given that the PowerPC applications could not instruct the CPU directly anymore, Rosetta would translate them first and send them on their way. This allowed those who were still using applications from that CPU architecture to continue using those applications on their new Intel systems. Support for that version of Rosetta was dropped in 2010.

Hold on. There’s more.

Rosetta 2 was introduced as a successor to the original version in 2020 when Apple released its Arm64 chips. This enabled those upgrading from the Intel chips to continue operating with their x86-based applications. History repeated itself as it was 14 years ago, and new Mac owners could continue apace.

How Is Rosetta Relevant In Docker’s Context? Why Is This A PSA?

Until recently, Docker did not have Rosetta available, and until later it wasn’t under the general settings. At the end of October, Docker publicly released version 4.25, which had the “Use Rosetta” setting available, moving it to General. Unfortunately, this setting was not turned on by default. If you, like me, were unaware of this, you would fail to run any x86 container.

This is where my issues began. Around the same time this version dropped, I needed to run an SQL server on my machine. Microsoft’s technologies notoriously do not work on Mac, and if they do, it’s at a limited capacity. There was no way around this either — I needed SQL to work on my machine. Everyone else was on a Windows machine. There was no other option

After a week of research, I encountered Azure Edge and was able to set that up on my Mac. However, further research proved some concerns true; Edge was missing some features contained in SQL. I wasn’t sure if I was going to need them, so I persisted in trying to run SQL.

At some point later I encountered a Reddit thread. The original poster had a similar issue to me  they needed to run an x86 container on Apple Silicon. The thread itself had gathered little attention. One reply instructed the original poster to enable a setting under “Features in development.” They suggested, “Use Rosetta for x86/amd64 emulation on Apple Silicon.” I realized this was my solution, so I opened my Docker development settings, only to realize it didn’t exist.

…So Now What?

I Googled the setting and found the Docker patch notes mentioning how it was now a stable feature. I then opened the general settings and there it was. A click, a restart, and a command later, and SQL was chugging along in Docker.

Why wasn’t this enabled by default?!

After talking about this with my peers, we concluded nothing was stopping the setting from being enabled immediately. I imagine there’s probably some reason behind this — maybe it’s resource-intensive? As I type this, my container is utilizing 4 GB of RAM, so maybe that is part of why.

That said, if you’re unconcerned with resource usage, it won’t hurt to have this option enabled. It’s one less thing to worry about if ever there’s a time when your project operates on x86 hardware. Please, turn it on and save yourself the future headache.

TL;DR

Docker settings > General > Check Use Virtualization Framework > Check Use Rosetta for x86/amd64 emulation on Apple Silicon > Click Apply & Restart. Have fun!

 
Conversation

Join the conversation

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