stopping multiple containers gracefully, is the docker stop `--time` option for each container or for all containers?

319 views Asked by At

I'm trying to stop all containers gracefully. So I want to give each container 60 seconds. I see that you can do:

docker stop --time=60 $(docker container ls -q)

is the --time=60 for each container or do all the containers only get 60 seconds?

  • for example: if one container takes 59 seconds to stop... does that mean the next container only gets 1 second to stop?
  • if all the containers get 60 seconds... then i will do a bash for loop and do docker stop on each container... to ensure they each get 60 seconds.
1

There are 1 answers

0
Hector Vido On

The parameter --time=60 are considered for each container.

Docker client do HTTP requests for under the hood. When you pass more than one argument like this:

docker stop --time=60 $(docker container ls -q)

Docker client will send as many requests as the values returned by your shubshell docker container ls -q, each request will have a --time for their own.

Now that we know docker do requests to "docker api", we can look on API Docs and notice there is no endpoint to stop or kill a lot of containers, only one per call.