Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker stack "--force-recreate" in swarm mode using compose file

Is it possible to do a force recreation of containers using compose file in docker swarm mode ? (I am aware of using HEALTHCHECK in Dockerfile)

Currently i have to remove the stack first & then deploy it again -

$ docker stack deploy -c stg-sm-deploy-compose.yml --with-registry-auth MY-APP

$ docker stack rm MY-APP

$ docker stack deploy -c stg-sm-deploy-compose.yml --with-registry-auth MY-APP

Is there any possibility that above 3 commands can be replaced by -

$ docker stack deploy -c stg-sm-deploy-compose.yml --with-registry-auth MY-APP --force-recreate

like image 1000
vivekyad4v Avatar asked Aug 27 '26 21:08

vivekyad4v


1 Answers

For any service created inside that stack that didn't change, you can use:

docker service update --force $service

which will force a rolling update of that service.

To recreate everything from a stack, enter your stack name as $stack in:

docker stack services -q $stack \
  | while read service; do
    docker service update --force $service
  done
like image 80
BMitch Avatar answered Aug 29 '26 13:08

BMitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!