Thanks to Dump Tiger and Bjørn, I got to know the xargs command.
One thing that I don't like so much, when I'm starting/stopping Docker containers quite often, is that they'll polute your disc space (depending on the image size).
docker ps -a | grep 'Exited (' | cut -d ' ' -f1 | xargs docker rm
The pipe shown above does the following:
- List all Docker containers
- Filter the list, so that only those lines that contain the string 'Exited (' will be returned
- From all returned lines, cut of the first row (the container ID) by splitting each line on all whitespaces
- Now that we've a list of container IDs, we can pipe each container ID into docker rm by using xargs