Running Ruby, Node, Python and Docker on the new Apple Silicon architecture?

18,554

Solution 1

Programming languages such as Ruby, Node and Python should run on Apple M1 Chip but Docker is not supported as of now (They are working on it)

Docker for Mac Issue https://github.com/docker/for-mac/issues/4733

Docker team might be working on fixing the issue as per this: https://github.com/docker/roadmap/issues/142

My Recommendation: Get it now only if you want to build iOS application. Since most of the people don't have the laptop right now, we might end up with a lot of other issues.

UPDATE: This one is more appropriate answer now: https://stackoverflow.com/a/65253659/8216911

Solution 2

I've tried many things and had some real trouble getting things working, but in the end, here is the simplest way I've found to get Docker running on a new Mac Silicon M1 chip.

Docker does not natively work, VirtualBox doesn't work, Parallels doesn't work, ... in the end, it goes down to using UTM to create a Virtual Machine, install Ubuntu server on it. Once you have that, you can install whatever you want on it (Docker, Node JS, Apache, PHP, MariaDB, ...).

Then you set eveything up so you can use all your favorite Mac OS tools ( Terminal, Transmit, VS Code, Safari ... ) to work, just as if you had all that on your local file system.

1 - Download Linux installation disk

Grab an ARM linux distribution. I took Ubuntu server 20.04 LTS: https://cdimage.ubuntu.com/releases/20.04/release/ubuntu-20.04.1-live-server-arm64.iso
It's 922 MB.

I got it from here: https://ubuntu.com/download/server/arm

You can chose any linux distribution, but just make sure you get the ARM version (some distributions don't have one).

2 - Download UTM

UTM is a virtualisation software that is mainly aimed at IOs devices, but it works on Mac OS too.
https://github.com/utmapp/UTM/releases/download/v2.0.14/UTM.dmg
That one is 255 MB.
Future versions will be available from here: https://github.com/utmapp/UTM/releases/
Simply download the package, open it, and launch the application that is inside.

3 - Create your VM

Create your new VM, attach the linux installation disk to it and launch the VM following these steps here:
https://github.com/utmapp/UTM/wiki/Install-Ubuntu-ARM64-on-Apple-M1

Basically:

  1. click Create a New VM
  2. in the Information tab: choose a name and an icon for your VM
  3. in the System tab:
    1. in Hardware choose ARM64 (aarch64) architecture
    2. give it some memory (how about 4 GB ...)
  4. in the Drives tab:
    1. create your main drive with New Drive, interface VirtIO and choose the size you want (I chose 20 480 MB), then click Create.
    2. create the CD drive with New Drive, check Removable, interface USB, click Create
  5. Save the VM
  6. Select your shiny new VM in the sidebar and in the bottom right corner, click Browse and select your Linux installation ISO virtual disk.

You can now launch the VM, it will boot on the Linux installation CD: install Linux.

During this classic installation process, you will be asked to create a user account on the linux system (let's call it bob). When the installation is finished, shut down the VM and extract the installation disk before rebooting.

4 - Working inside your VM

When you restart the VM, you get a terminal asking you to log into Linux, using the username and password you created during installation.

You can now install Docker, openSSH-server, nodeJS, using classic apt-get commands.

5 - Working in your VM from MacOS

If you failed like to me chose the right keyboard, you might have trouble typing some special characters. The best way to work with your VM is now to work from outside of it.

Stop the VM (sudo shutdown -h now if you are already inside the shell) and go back to UTM:
Select your VM in the left side panel and click the top right button to edit the VM again :
Go to the Network tab and in front of Port Forward, click New.
You need to manually add a new port forwarding directive for each port in your VM you want to access from your Mac OS Host.

For example for SSH: in the new port forward form, simply write 22 in Guest Port and what you want in Host Port (let's say 3022).

Now you can restart your VM and in a normal Mac OS Terminal, you can log into your VM with
ssh -p 3022 bob@localhost

If you don't want to type your password each time, copy the content of ~/.ssh/id_rsa.pub (from Mac OS) inside a newly created /home/bob/.ssh/authorized_keys text file, inside the VM.

6 - copying files via sftp

Sadly, I did not manage to access the content of the VM directly with the finder. I had to use the famous FTP client Transmit.

Create a new connection with:
Protocol: SFTP
Host: localhost
User: bob
Password: [your password]
Port: 3022
(yes, the port is the same as SSH)

You can now freely explore and copy files to and from your VM.

Oh but wait ... there is more!

7 - working with VS Code on your VM

Now you can also work on your VM, from your Mac OS VS Code, installing the Remote Development extention: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

Once the extention is installed, click on the green >< sign at the bottom left of your VS Code window and choose Remote-SSH: connect to host ...
Choose add new SSH host and type ssh -p 3022 bob@localhost

Now you can work in VS Code on a project inside your VM just as if it was in your local file system.

I do some Nuxt.js development that calls an API powered with Apache / PHP / MySQL (had to switch to MariaDB because I could not find an ARM version of MySQL that was working) that is all running in different Docker containers inside the VM using docker-compose.

Having Port Forwarded the guest 3000 port to the host 3000 port, I can browser the front end with Safari just as if it was all running natively on Mac OS.

I hope this all saves you some time.

Share:
18,554
Igor P
Author by

Igor P

Christian, husband, regular guy.

Updated on June 06, 2022

Comments

  • Igor P
    Igor P almost 2 years

    How do you get a Ruby, Python and Node.js development environments running on Apple Silicon architecture. What about virtualization software e.g. Docker?