Docker Engine with multipass on macOS
Now that Docker desktop is no longer free, it is useful to have easy-to-use alternatives for running docker on macOS.
I am not ready to make the jump to podman yet as outline in this great guide
So I have taken inspiration from the above article and remixed it to work with docker.
First, install homebrew
Once you have that install multipass and the docker client.
brew install multipass docker
Now make a yaml file save it as docker.yaml
. Here is the one I used, make sure to replace your public key. (Make sure you have an ssh key pair, I am using a rsa key.)
---
users:
- name: ubuntu
sudo: ALL=(ALL) NOPASSWD:ALL
ssh-authorized-keys:
- ssh-rsa AAAAB3Nza....package_update: true
packages:
- docker
- avahi-daemon
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-releaseruncmd:
- sudo curl -fsSL https://get.docker.com | sudo bash
- sudo systemctl enable docker
- sudo systemctl enable -s HUP ssh
- sudo groupadd docker
- sudo usermod -aG docker ubuntu
Once you have that in a file run this command to start it up. This is using 2 CPUs and 4G of ram
multipass launch -c 2 -m 2G -d 4G -n docker 20.04 --cloud-init docker.yaml
It will take a few mins to build and start. Once it does you can see what is running with
multipass list
One nice extra we are using is mDNS with Avahi so you can try to ssh into your machine with the following command. Make sure to try this and accept the keys.
ssh ubuntu@docker.local
Once you are in you can make sure docker is working like this
docker info
Cool, if everything looks good go back out to your local host and try to use the docker client to connect to the remote docker engine like this
DOCKER_HOST="ssh://ubuntu@docker.local" docker ps
Great if you don’t see any errors you were able to connect.
Next, you can add this to your ~/.bash_profile
to always use this DOCKER_HOST
export DOCKER_HOST="ssh://ubuntu@docker.local"
Alternatively, if you want to be more advanced you can try the docker contexts.