Ooh Docker Contexts!

I discovered Docker Contexts the other day. It’s pretty useful.

I have an iMac with 8GB or RAM and usually I run Docker on it but ideally I’d not like to. The minimum amount of RAM the Docker VM needs is 1GB so that’s that much less RAM for the less of the system. I don’t really want to run Docker containers from the iMac so all I am really looking for is just the Docker commands and the ability to run them remotely against a different Docker instance – say the one running on my Raspberry Pi.

I had previously tackled this problem via an alias I made at the end of this post here. Now I realize I don’t even need that. So here’s what I did:

  1. Installed Docker Desktop for macOS. Then I shut it down from the menu bar, and also ensured it is not setup to start automatically on login (that’s the default anyways I think).
  2. This gives me the Docker commands so I did the following:

And that’s it. Now I can run any of my Docker commands like docker ps and docker run and it will run against the Docker instance on the Raspberry Pi. This also works for docker-compose – nothing additional to do.

Above I switched my default context to the remote one but I could have also used a --context switch to specify a context name per command.

As an aside this works with Azure and AWS too. So I have an Azure context too that lets me push containers out to Azure.