Docker Swarm: how to do a rolling update on demand?

258 Views Asked by At

How can one execute a rolling update on a docker swarm service on demand?

My scenario: I have a Github Action that will test my code, build the docker containers and pull to Docker Hub. After all this I want to do rolling update to a specific swarm service.

How can this be done?

1

There are 1 best solutions below

1
Garuno On

So the question is how to execute the command inside GitHub Actions. I would say just like any other command:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Execute docker swarm
        run: docker stack deploy -c compose-file.yml
        env:
          DOCKER_HOST: example.com

This requires you to expose your docker daemon to the outside world, which you should probably only do, if you have some kind of authentication in place. One way to do this is documented here. Another way would be to use SSH and execute the command on the server itself, for example with this.