I saw this command:

docker inspect --format '{{.State.Running}}' $(docker ps -lq)

and this:

docker ps -l -q|while read cid b; do docker inspect -f '{{ .State.Running }}' $cid; done;

My question is why it cannot be written as:

docker ps -l -q|docker inspect -f '{{.State.Running}}'

If that was because docker inspect does not work with pipe, how can I know which command can and which cannot?


Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.

You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.

  • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal. – Kusalananda Nov 25 '18 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.