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}'



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>8080/tcp,>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.

  • 2
    You know that the -q flag gives output well suited for further processing? Aug 4 '20 at 18:22
  • yes @ThorbjørnRavnAndersen but it's also to try and learn a bit of awk usage Aug 5 '20 at 5:22

With awk, you can skip the first line (or record) using NR > 1:

docker container ls | awk 'NR > 1 {print $1}'

But you don't need that. You can just tell docker to format the output:

% docker container ls --format '{{.ID}}'
  • 1
    This is a good answer since format is really powerful for more complicated cases, but it's worth knowing that for simple cases like thisdocker container ls -q will do exactly what you want.
    – jdf
    Aug 5 '20 at 22:14

The command you're looking for is tail -n +2:

docker container ls | awk '{print $1}' | 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.

$ docker container ls -q

Many command line tools use similar conventions like --help that give more detailed information about usage options. Here is the output of docker container ls --help:

# docker container ls --help

Usage:  docker container ls [OPTIONS]

List containers

  ls, ps, list

  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes

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.