cli icon indicating copy to clipboard operation
cli copied to clipboard

Unclear what a type is when using docker inspect

Open rcjsuen opened this issue 9 months ago • 2 comments

Description

The documentation for --type just says Return JSON for specified type. Could we improve this to include all the types or at least some of the commonly used ones?

$ docker -v
Docker version 28.1.1, build 4eba377
$ docker inspect --help
Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format output using a custom template:
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type

rcjsuen avatar May 04 '25 13:05 rcjsuen

Thanks for reporting; the list of options accepted for --type is documented in the CLI reference documentation; https://docs.docker.com/reference/cli/docker/inspect/#type

For most types, there's also an equivalent subcommand for each type, for example docker inspect --type container <something> is equivalent to docker container inspect <something>. Similarly, for other types;

  • docker container inspect
  • docker image inspect
  • docker volume inspect
  • docker service inspect
  • docker node inspect
  • docker config inspect
  • docker secret inspect
  • docker service inspect
  • docker network inspect
  • docker plugin inspect

I suspect the main reason for not including the list of accepted options in the flag description is that this would make the description very long, which would limit readability (but perhaps we should have a look if it would still be "reasonably" readable.

One thing we can improve is to make sure there's shell (tab) completion for this flag, so that shell-completion can provide hints on what options can be used. I have a branch doing so and will open a pull request for that.

For the flag-description, I'll have a look at a separate follow-up, as we'll have to discuss if the output is still readable with the large number of options possible.

thaJeztah avatar May 06 '25 13:05 thaJeztah

Opened a PR for the tab-completion;

  • https://github.com/docker/cli/pull/6052

thaJeztah avatar May 06 '25 13:05 thaJeztah