-1

I have to stop all container's with specific string in name. For example there is 4 container's with name's : apache1 apache2 apache3 jboos

I try to stop only this with "apache" in the name. Is there any native way in PODMAN to stop all containers with a specific name?

I can list the containers with the specified name:

podman ps -a -f name=apache

But is it possible to stop only container's from above output ?

Or maybe there is another way to achieve this result?

  • Have you considered switching to docker? Asking because you tagged the question as a docker question. – BMitch Jan 21 '22 at 17:09
  • Maybe relevant. The very latest Podman has new filtering functionality: https://github.com/containers/podman/releases/tag/v4.0.0-rc2 _All commands that support filtering their output based on labels (e.g. podman volume ls, podman ps) now support labels specified using regular expressions (e.g. --filter label=some.prefix.com/key/*)._ – Erik Sjölund Jan 22 '22 at 07:10

1 Answers1

0

You can get a list of the container ids using

docker ps -q -f name=apache

Then you can use that somewhere else. I'm not familiar with podman, but you can kill the containers using docker like this

docker kill $(docker ps -q -f name=apache)

Please be aware that this will kill any container with a name that contains 'apache'. A container called 'im-nginx-and-not-apache' will match and will be killed.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • Thanks for the answer, unfortunately in the case of podmana it is not successful podman kill $(podman ps -q -f name=apache) Error: you must provide at least one name or id – CbrChannel Jan 21 '22 at 20:38
  • Does `podman ps -q -f name=apache` list any container ids? The error seems to indicate that it doesn't. – Hans Kilian Jan 21 '22 at 21:53
  • 2
    Thank you ! That's working: podman rm -f $(podman ps -a -q -f name=apache) – CbrChannel Jan 24 '22 at 10:04