The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

lume/src/notes: docker build over ssh

Signed-off-by: Xe Iaso <me@xeiaso.net>

Xe Iaso 34d35c6e 119cf6dd

+67
+67
lume/src/notes/2024/docker-build-over-ssh.mdx
··· 1 + --- 2 + title: "Docker builds over SSH" 3 + desc: "Plan 9 clustering at home" 4 + date: 2024-10-18 5 + tags: 6 + - docker 7 + - ssh 8 + - devops 9 + --- 10 + 11 + 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. 12 + 13 + For example, here's what it looks like by default on Linux: 14 + 15 + ``` 16 + $ docker context ls 17 + NAME DESCRIPTION DOCKER ENDPOINT ERROR 18 + default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock 19 + ``` 20 + 21 + You can add contexts with the `docker context create` command, and also point those contexts to remote hosts over SSH: 22 + 23 + ``` 24 + docker context create \ 25 + --docker host=ssh://cadey@pneuma \ 26 + --description "Iustorum autem semita quasi lux splendens procedit et crescit usque ad perfectam diem" \ 27 + pneuma 28 + ``` 29 + 30 + Then whenever you need to deal with the remote host for a command: 31 + 32 + ``` 33 + docker --context pneuma pull alpine:edge 34 + ``` 35 + 36 + You can set it as the default with `docker context use`: 37 + 38 + ``` 39 + docker context use pneuma 40 + ``` 41 + 42 + 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: 43 + 44 + ``` 45 + $ hostname 46 + shiroko 47 + 48 + $ docker run -it --rm --network host alpine:edge 49 + # hostname 50 + pneuma 51 + ``` 52 + 53 + This even works for tools like [Earthly](https://earthly.dev): 54 + 55 + ``` 56 + $ earthly +all 57 + (...) 58 + 59 + $ docker images 60 + REPOSITORY TAG IMAGE ID CREATED SIZE 61 + ghcr.io/xe/site/bin earthly 828d989bb3b3 2 minutes ago 263MB 62 + ghcr.io/xe/site/patreon latest 9d3e945e7d6f 2 minutes ago 23.8MB 63 + ``` 64 + 65 + 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! 66 + 67 + This is cool as hell!