I'm looking to use tools along the lines of:
- grep
- sed
- AWK
to work with Docker.
Listing containers:
docker container ls | awk '{print $1}'
Results:
CONTAINER
490e3d669259
a44230a617e1
How can I omit the "header"?
Here's the full output for docker container ls
should that prove useful:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
490e3d669259 jetty "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp quirky_antonelli
a44230a617e1 jetty "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 8080/tcp goofy_hamilton
I am just looking for the values under the container heading.
With awk, you can skip the first line (or record) using
NR > 1
:But you don't need that. You can just tell
docker
to format the output:The command you're looking for is
tail -n +2
:Explanation here (there is also an option using
sed
- guess you have to try which is fastest).Docker gives you more control so that you don't actually need to use a second command piped to do post-processing. In this instance you can just use the
--quiet|-q
option.Many command line tools use similar conventions like
--help
that give more detailed information about usage options. Here is the output ofdocker container ls --help
: