Monday, 14 July 2025

On the other hand... Docker Swarm

G'day:

(That's a callback of sorts to today's earlier article Clustering a PHP app with Kubernetes (or "Why the f*** do I put myself through this shite?"), which clocks in a ~5500 words).

To do the equivalent in a dev environment with Docker Swarm, one does this:

$ docker swarm init --advertise-addr 127.0.0.1
Swarm initialized: current node (fn3o7kmnep81j28xjsth094z6) is now a manager.

And then one does this:

$ docker service create \
    --name php \
    --replicas 3 \
    --publish published=9000,target=9000 \
    --env-file docker/envVars.public \
    --env-file docker/php/envVars.public \
    --env-file docker/php/envVars.prod.public \
    --env-file docker/envVars.private \
    --env-file docker/php/envVars.private \
    --host host.docker.internal:host-gateway \
    adamcameron/php8-on-k8s:latest
    
fw3j4qtrpe2lgesr0x3tbeiaa
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service fw3j4qtrpe2lgesr0x3tbeiaa converged    
    

And then… erm… no actually that's it. That works. Done.


Obviously this (and the other article) and for dev-ony messing around with things, and I have no idea how to manage Kubernetes or Docker Swarm. But one took a week to work out WTF. And the other took about an hour. Inciuding the time it's gonna take to write this.

Source code has been updated in the repo I was using before, and tagged as 0.9. It's changes to the README.md, and making a label more generic ("Pod name" => "Instance ID").

Oh, and I was working from these docs: Manuals / Docker Engine / Swarm mode. Beyond a point I was able to guess what I needed to do.

Righto.

--
Adam