Auto Redeploy swarm services via Webhooks
Adopted from Shephard to enabled unsupervised redeploy of services deployed in docker swarm. Similar to how it used to be in Docker Cloud when it was alive.
- Deploy a service using
riyasdeen/docker-swarm-redeploy:latest
. - Please replace
secure-token
with a secure token value, can be any string. Request from docker hub webhook will be authenticated with this token
docker service create --name auto-redeploy \
--replicas 1 \
--constraint "node.role==manager" \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--env TOKEN=secure-token
--publish published=5000,target=80
riyasdeen/docker-swarm-redeploy
If you are using private images in docker registry then your registry credentials can be provided via Docker Secrets.
Create a Secret names registry-auth
with secret value as { username: your-docker-username, password: your-docker-password }
. Please replace your-docker-username
and your-docker-password
with your docker credentials
The last argument is set to
-
, which indicates that the input is read from standard input.
$ docker secret create registry-auth -
{ username: your-docker-username, password: your-docker-password }
Add a webhook in Docker hub for the repository that you would like to be redeployed when a new image is pushed. Please replace your-server-endpoint
with public end point of docker-swarm-redeploy, and secure-token
with token used in step 1
That's it!!! Every time a new image is pushed to your repository, the services using that image will be redeployed with the new image.
docker-swarm-redeploy just triggers a service update of all services deployed with image name & tag as posted by Docker Hub.
Most of the work is thankfully done by Docker which resolves the image tag, checks the registry for a newer version and updates running container tasks as needed.
Also, Docker handles all the work of applying rolling updates. So at least with replicated services, there should be no noticeable downtime.