skip to Main Content

How to use --format option of docker inspect to get its output as a table.
Following the documentation I used --format 'table ...' as an option with docker ps and it worked fine, but docker inspect seems to ignore it.

example:

echo "docker ps as table"
docker ps -a --format 'table {{.Names}}t{{.Image}}'

echo "docker inspect as table"
docker ps --quiet | xargs --no-run-if-empty docker inspect 
--format 'table {{.Name}}t{{.Config.Image}}'

produces the output:

docker ps as table
NAMES                     IMAGE
tmp-php-7.3-cli-buster    tmp-php:7.3-cli-buster
tmp-mysql-8.0.19-client   mysql:8
tmp-mysql-8.0.19          tmp-mysql:8.0.19
tmp-nginx-1.17.8          tmp-nginx:1.17.8
tmp-php-7.3-fpm-buster    tmp-php:7.3-fpm-buster
tmp-node-13.8.0-buster    tmp-node:13.8.0-buster
docker inspect as table
table /tmp-php-7.3-cli-busterttmp-php:7.3-cli-buster
table /tmp-mysql-8.0.19-clienttmysql:8
table /tmp-mysql-8.0.19ttmp-mysql:8.0.19
table /tmp-nginx-1.17.8ttmp-nginx:1.17.8
table /tmp-php-7.3-fpm-busterttmp-php:7.3-fpm-buster
table /tmp-node-13.8.0-busterttmp-node:13.8.0-buster

2

Answers


  1. Looks like docker inspect currently can’t ouput tables, see this GitHub issue:

    I got here because I’ve tried to output table too, but unfortunately, all I can do is quote the comment from the issue:

    TLDR; docker inspect deals with JSON output and thus JSON output templates, versus the formatting strings you’d expect from other commands (such as docker stats)

    Which is essentially why table isn’t working as expected and coming back as raw.

    Login or Signup to reply.
  2. I managed to get a "table"-like output similar to docker stats. Mainly by utilizing the column command.

    For example with this command:

    docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}" | column -t -s ' '
    

    Or if you also want some fancy headings:

    (echo "NAME USER"; docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}") | column -t -s ' '
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search