Docker running on MacOS with Apple M1 chip in one command

Recently, Docker has announced that Docker Desktop will be a paid subscription for corporate users. Couple this with the latest Apple M1 chipset on the latest Macbooks, that still has limited support by the Virtual Machine vendors, and the community has a reason to look for alternatives.

Canonical (the makers of Ubuntu) has released Multipass, a dedicated Ubuntu VM-as-a-Service capability that fully supports the Apple M1 chip. With this, and in about 5 minutes of your time (depending on download speeds), you can get Docker running on your M1 Macbook.

Edit: I have created a script to automate the entire process!

Here is the repo: https://gitlab.com/scottbri/docker-on-m1

Installation

This installation assumes that homebrew is already installed. The script will fully automate the installation of docker, docker-compose, and multipass using homebrew.

We will use the name dockervm for the multipass ubuntu vm instance name.

Usage

bash -c “$(curl -fsSL https://gitlab.com/scottbri/docker-on-m1/-/raw/main/install.sh)”

How to do it manually:

On MacOS

Install Multipass

brew install multipass
multipass shell

Install Docker

In your new Ubuntu vm:

sudo apt-get update

sudo apt-get -y install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get -y install docker-ce docker-ce-cli containerd.io

sudo docker run hello-world

Allow user execution of docker command:

sudo groupadd docker

sudo usermod -aG docker $USER
# You must log out and log back in to get the docker command to work
# docker run hello-world

Enable Docker services and expose dockerd externally:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

echo '
{"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}' | sudo tee /etc/docker/daemon.json > /dev/null

sudo mkdir -p /etc/systemd/system/docker.service.d/

echo '[Service]
ExecStart=
ExecStart=/usr/bin/dockerd' | sudo tee /etc/systemd/system/docker.service.d/override.conf > /dev/null

sudo systemctl daemon-reload

sudo systemctl restart docker.service

exit

Back in MacOS

Configure docker to point to the Ubuntu Docker Machine:

# primary is the default multipass instance name
# substitute for your instance if needed
export DOCKER_HOST="$(multipass info primary | awk '/IPv4:/ {print $2}'):2375"

docker run hello-world

In just a few steps you can get Docker running well in an Ubuntu VM on your Apple M1 chip. You can add the export DOCKER_HOST command to your .zshrc or other initialization script. Cheers!