Docker, Testcontainers and Apple Silicon

Posted on

As I am waiting for DHL to deliver new Mac Book Air with M1 chip, I am working on setting up my work environment on it. Well, just virtually preparing the setup as I do not have the machine yet. What I know is that almost every program for Intel based Macs should be running on the new M1 via Rosetta 2 emulation. But some programs I use, such as Docker, will not run until there is native version of it.

Good thing about Docker is that you can run its daemon on other machine and instruct your machine to connect to it just by setting DOCKER_HOST environment variable. That means either exposing port that daemon runs on, or to establish a ssh tunnel and make that port or unix socket available on your local machine. So I am using command like
ssh -L 2375:remote.docker.host:/var/run/docker.sock user@remote.docker.host
and setting
export DOCKER_HOST=tcp://localhost:2375
After doing this all docker containers run on remote.docker.host.

The only problem I had was when using Testcontainers that it expected all containers it started to be available at localhost:xxx, so quick read of documentation showed simple solution:
export TESTCONTAINERS_HOST_OVERRIDE=remote.docker.host