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:
- 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).
- This gives me the Docker commands so I did the following:
1 2 3 |
# create a docker context called "pi" which points to the Docker instance running on the device "raspberrypi" and connects to it via SSH docker context create pi --description "docker on my pi" --docker "host=ssh://raspberrypi" |
1 2 |
# switch to this context docker context use pi |
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.