Take Docker. We often want to find out which container is running something specific. Once we find our container, we want to “exec” a shell into it, or we want to kill it.
Here’s the best way that doesn’t mess with cut/sed/awk:
Here’s how to use it in practice, by killing the web container:
$ docker rm -f $(docker ps –filter ancestor=web,status=running –quiet)
Also, here’s how to use the same technique to hop into the web container, and run a shell. This I use constantly, so I can examine a container to see what’s going on, what it’s doing, or what it’s not doing:
$ docker exec -it $(docker ps –filter ancestor=web,status=running –quiet) bash