···11+---
22+title: "Docker builds over SSH"
33+desc: "Plan 9 clustering at home"
44+date: 2024-10-18
55+tags:
66+ - docker
77+ - ssh
88+ - devops
99+---
1010+1111+While on stream today, SlyEcho pointed out that you can set `DOCKER_HOST=ssh://...` to have the Docker client seamlessly do builds and the like over SSH instead of using the local computer's Docker daemon. In the process of playing with this, I found the [`docker context`](https://docs.docker.com/engine/manage-resources/contexts/) command. This is cool as hell, it allows you to manage multiple Docker daemons the same way that you would with Kubernetes clusters.
1212+1313+For example, here's what it looks like by default on Linux:
1414+1515+```
1616+$ docker context ls
1717+NAME DESCRIPTION DOCKER ENDPOINT ERROR
1818+default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock
1919+```
2020+2121+You can add contexts with the `docker context create` command, and also point those contexts to remote hosts over SSH:
2222+2323+```
2424+docker context create \
2525+ --docker host=ssh://cadey@pneuma \
2626+ --description "Iustorum autem semita quasi lux splendens procedit et crescit usque ad perfectam diem" \
2727+ pneuma
2828+```
2929+3030+Then whenever you need to deal with the remote host for a command:
3131+3232+```
3333+docker --context pneuma pull alpine:edge
3434+```
3535+3636+You can set it as the default with `docker context use`:
3737+3838+```
3939+docker context use pneuma
4040+```
4141+4242+And then whenever you're doing something with Docker, it will seamlessly SSH into the machine `pneuma`, do the operation, and then return the result. This works for building and running containers too:
4343+4444+```
4545+$ hostname
4646+shiroko
4747+4848+$ docker run -it --rm --network host alpine:edge
4949+# hostname
5050+pneuma
5151+```
5252+5353+This even works for tools like [Earthly](https://earthly.dev):
5454+5555+```
5656+$ earthly +all
5757+(...)
5858+5959+$ docker images
6060+REPOSITORY TAG IMAGE ID CREATED SIZE
6161+ghcr.io/xe/site/bin earthly 828d989bb3b3 2 minutes ago 263MB
6262+ghcr.io/xe/site/patreon latest 9d3e945e7d6f 2 minutes ago 23.8MB
6363+```
6464+6565+This means that even though I've somehow broken the Docker desktop app on my gaming PC that I stream from, I can still use Docker via one of my homelab machines!
6666+6767+This is cool as hell!