How to run Linux x86_64 binary on ARM-based Mac M1

Suppose you want to:

  • Run Linux x32 binary on ARM-based Mac
  • Run Linux x64 binary on ARM-based Mac
  • Run Linux x32 binary on Mac M1
  • Run Linux x63 binary on Mac M1
  • Run Linux x86_64 on ARM-based Mac
  • Run Linux x86_64 on Mac M1

Honestly, I don’t know, why this option is never mentioned in the internet. We need just to create an empty Docker container (based on Linux image), mount the local directory with your binary and just run it!

No QEMU, no Parallels, no RosettaVM or other stuff needed. Just follow these steps.

Step 1. Install Docker. After installation go to Docker Settings -> Features in development -> Check “Use Rosetta for x86/amd64 emulation on Apple Silicon” and save.

Step 2. Create file named Dockerfile with content:

FROM --platform=linux/amd64 ubuntu:23.10
RUN apt-get update && apt-get install -y mc

I recommend installing mc (it is Midnight Commander) in order to have convenient way to browse files inside your container later. You may later just type “mc” in container’s terminal and thereby open file browser.

If you need JVM or other stuff, just add those this way:

FROM --platform=linux/amd64 ubuntu:23.10
RUN apt-get update && apt-get install -y mc && apt-get install -y default-jre && whatever

Step 3. Build & run container with just one command (execute this command from the directory with the file we created on the previous step):

docker run --platform linux/amd64 -td --name your-container-name \
    -v /Users/<user-name>/<folder-to-mount>:/target \
    -it $(docker build -q .)

This folder: /Users/<user-name>/<folder-to-mount> will be mounted to /target inside your container.

Step 4. Connect to the container:

docker exec -it your-container-name /bin/bash

After you’ll execute this command, you may interact with your container directly.

For example, open Midnight Commander (type mc to the shell after the command above), navigate to /taget and run your binary.

That’s all.

Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

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