docker 检查 - 将其输出格式化为 table
docker inspect - format its output as a table
如何使用 docker inspect
的 --format
选项将其输出作为 table。
在 documentation 之后,我使用 --format 'table ...'
作为 docker ps
的选项并且它工作正常,但 docker inspect
似乎忽略了它。
示例:
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}}'
产生输出:
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-buster\ttmp-php:7.3-cli-buster
table /tmp-mysql-8.0.19-client\tmysql:8
table /tmp-mysql-8.0.19\ttmp-mysql:8.0.19
table /tmp-nginx-1.17.8\ttmp-nginx:1.17.8
table /tmp-php-7.3-fpm-buster\ttmp-php:7.3-fpm-buster
table /tmp-node-13.8.0-buster\ttmp-node:13.8.0-buster
看起来 docker inspect
目前无法输出 tables,请参阅此 GitHub 问题:
我来这里是因为我也尝试输出table,但不幸的是,我只能引用该问题的评论:
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.
我设法得到类似于 docker stats
的类似“table”的输出。主要是利用column
命令。
例如使用此命令:
docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}" | column -t -s ' '
或者如果您还想要一些花哨的标题:
(echo "NAME USER"; docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}") | column -t -s ' '
如何使用 docker inspect
的 --format
选项将其输出作为 table。
在 documentation 之后,我使用 --format 'table ...'
作为 docker ps
的选项并且它工作正常,但 docker inspect
似乎忽略了它。
示例:
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}}'
产生输出:
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-buster\ttmp-php:7.3-cli-buster
table /tmp-mysql-8.0.19-client\tmysql:8
table /tmp-mysql-8.0.19\ttmp-mysql:8.0.19
table /tmp-nginx-1.17.8\ttmp-nginx:1.17.8
table /tmp-php-7.3-fpm-buster\ttmp-php:7.3-fpm-buster
table /tmp-node-13.8.0-buster\ttmp-node:13.8.0-buster
看起来 docker inspect
目前无法输出 tables,请参阅此 GitHub 问题:
我来这里是因为我也尝试输出table,但不幸的是,我只能引用该问题的评论:
TLDR;
docker inspect
deals with JSON output and thus JSON output templates, versus the formatting strings you'd expect from other commands (such asdocker stats
)
...
Which is essentially why table isn't working as expected and coming back as raw.
我设法得到类似于 docker stats
的类似“table”的输出。主要是利用column
命令。
例如使用此命令:
docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}" | column -t -s ' '
或者如果您还想要一些花哨的标题:
(echo "NAME USER"; docker inspect $(docker ps -q) --format "{{.Name}} {{.Config.User}}") | column -t -s ' '