Remove old containers after running "docker service update" on a swarm cluster

That is the task history. A limited number of previous containers are kept when you update a service. You can delete them with docker container rm or run docker swarm update --task-history-limit 0 to disable this funtionality. The next update will then remove the old containers. But I think it can be useful when you update a service and something goes wrong. You can roll back and keep not just the previous configuration but the previous container. The stopped container will run again and the new version will be stopped.

ta@ta-mb  ~ 
 »  docker ps -a
CONTAINER ID   IMAGE       COMMAND              CREATED              STATUS                          PORTS     NAMES
044a16fcf4b0   httpd:2.4   "httpd-foreground"   About a minute ago   Up About a minute               80/tcp    httpd.1.m9hc3a4r5xi2m01s4sl7d00ig
0f054bca58d1   httpd:2.4   "httpd-foreground"   8 minutes ago        Exited (0) About a minute ago             httpd.1.f3xlnlnqg095zpus6rzs9vyzh


 ta@ta-mb  ~ 
 »  docker service rollback httpd
httpd
rollback: manually requested rollback
overall progress: rolling back update: 1 out of 1 tasks
1/1: running   [>                                                  ]
verify: Service converged


 ta@ta-mb  ~ 
 »  docker ps -a
CONTAINER ID   IMAGE       COMMAND              CREATED          STATUS                     PORTS     NAMES
c05d2205173d   httpd:2.4   "httpd-foreground"   12 seconds ago   Up 7 seconds               80/tcp    httpd.1.55m1syhjrc9bx16ja3urosvue
044a16fcf4b0   httpd:2.4   "httpd-foreground"   2 minutes ago    Exited (0) 8 seconds ago             httpd.1.m9hc3a4r5xi2m01s4sl7d00ig


 ta@ta-mb  ~ 
 »  docker service rollback httpd
httpd
rollback: manually requested rollback
overall progress: rolling back update: 1 out of 1 tasks
1/1: running   [>                                                  ]
verify: Service converged


 ta@ta-mb  ~ 
 »  docker ps -a
CONTAINER ID   IMAGE       COMMAND              CREATED              STATUS                      PORTS     NAMES
1b5f100d870e   httpd:2.4   "httpd-foreground"   15 seconds ago       Up 9 seconds                80/tcp    httpd.1.i672ukc53x3pnvkfscr4fyq84
c05d2205173d   httpd:2.4   "httpd-foreground"   About a minute ago   Exited (0) 10 seconds ago             httpd.1.55m1syhjrc9bx16ja3urosvue

PS.: Since I finally understand what you wanted to know, I changed the topic title. Please don’t create a topic with such a general title that doesn’t say anithing about your problem.

1 Like