Docker on M1 Mac

Using Docker on an M1 Mac for day-to-day activities is still a pain; a lot of plugins we use don't support the platform switch, and even when executed manually in the terminal, QEMU is painfully slow (I gave up after about 10 minutes of it processing the db2start command...).

One way to 'solve' this, if you have an x86 computer, is to use Docker contexts. The process is very simple.

  1. Make sure you have Docker running on the target machine (in my case it's my 2017 MacBook Pro)
  2. Also make sure you have SSH (aka Remote Login) turned on on that machine
  3. Create a context on the M1 Mac: docker context create mbp --docker "host=ssh://[email protected]"
  4. Switch to that context: docker context use mbp

You should be able to do docker ps, and that should show you the running containers on the target machine.

On my setup (which is the default, I suppose), I immediately encountered a problem:

error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&target=&ulimits=null&version=1": command [ssh -l jakub -- jakubs-macbook-pro-2017 docker system dial-stdio] has exited with exit status 127, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=zsh:1: command not found: docker

Err... ok... command not found...? The problem was that when connecting via SSH, by default, the PATH is just /usr/bin:/bin:/usr/sbin:/sbin. To change it, I needed to modify /etc/ssh/sshd_config by enabling user environments: PermitUserEnvironment yes, and modifying the value of PATH in ~/.ssh/environment to include /usr/local/bin.

That made the whole setup work, and my old Mac is still useful, while not sounding like a jet taking off (and it can be kept away in the laundry room).