Member-only story

Automated Deployment on Docker Swarm

From GitHub to Docker Hub to Docker Swarm

--

Configuring automated deployment of an image to Docker Hub every time a change is pushed to a specific GitHub branch (or when a new release is tagged) is easy to do with Docker Hub user interface.

Docker Hub will automatically configure your GitHub repository to trigger this for you and is able to build different Docker images from different GitHub branches.

While it’s quite straightforward to setup and run a private registry, using Docker Hub is very cheap and provides automated image building, starting at only $7 a month for 5 private repositories.

This makes using DockerHub much more cost effective option than spending time setting up and maintaining your own pipeline for building images, which can easily end up costing that much in compute time and cloud storage alone.

Using docker-deploy-webhook

You can configure Docker Hub to call a webhook each time a new image is published.

Unfortunately, Docker Swarm does not integrate with Docker Hub to trigger deployments automatically out of the box, which is where docker-deploy-webhook comes in.

Using docker-deploy-webhook you can run a Docker Service to listen for webhooks from Docker Hub on a Docker Swarm cluster, and trigger deployment of the new image on a corresponding service.

The webhook works with private repositories on GitHub / Docker Hub and with self-hosted Docker Swarms You don’t need to use Docker Cloud to manage your Swarm to use this webhook.

The easist way to use docker-deploy-webhook is to fork it and configure it with the images you want to listen for updates to.

How it works

The key to how it works is actually in how the service is deployed:

docker service create \
--name docker-deploy-webhook \
--with-registry-auth \
--constraint "node.role==manager" \
--publish=8080:8080 \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
-e CONFIG="8080" \
-e CONFIG="production" \
-e TOKEN="123456ABCDEF" \
-e USERNAME="docker-hub-username" \
-e PASSWORD="docker-hub-password" \

--

--

No responses yet