0

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?

Fernando
  • 325
  • 2
  • 13
  • Does [this](https://stackoverflow.com/questions/50936208/how-can-i-update-the-latest-image-that-my-docker-service-stack-uses) answer your question? – Garuno Jan 23 '23 at 12:04
  • Thanks @Garuno. As I understood from there, the `docker stack deploy -c compose-file.yml` will reploy fetching the new image from the registry. But how can I call this docker command from an automated task, like Github Actions? – Fernando Jan 23 '23 at 14:28

1 Answers1

0

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.

Garuno
  • 1,935
  • 1
  • 9
  • 20
  • Thanks. The goal is to run the stack deploy on my server, triggered by Github Actions. The SSH idea is interesting. – Fernando Jan 23 '23 at 19:00