[Docker]docker Command Docker inspect

Source: Internet
Author: User
Docker InspectEstimated reading Time:2 minutes Description

Return low-level information on Docker objects Usage

Docker inspect [OPTIONS] name|id [name|id ...]
Options
Name, Shorthand Default Description
--format, F Format the output using the given go template
--size, S False Display Total File sizes If the type is container
--type Return JSON for specified type
Parent Command
Command Description
Docker The base command for the Docker CLI.
Extended Description

By default, Docker inspect'll render all results in a JSON array. If the container and image have the same name, this'll return container JSON for unspecified type. The If a format is specified, the given template would be executed for each result.

Go's Text/template package describes all the details of the format. examples Get a instance ' s IP address

For the most part, you can pick out any field from the JSON in a fairly straightforward manner.

$ docker Inspect--format= ' {{range. networksettings.networks}}{{. Ipaddress}}{{end} ' $INSTANCE _id
Get a instance ' s MAC address
$ docker Inspect--format= ' {{range. networksettings.networks}}{{. Macaddress}}{{end} ' $INSTANCE _id
Get an instance ' s log path
$ docker Inspect--format= ' {{. LogPath} ' $INSTANCE _id
Get an instance ' s image name
$ docker Inspect--format= ' {{. Config.image} ' $INSTANCE _id
List all Port bindings

can loop over arrays and maps in the results to produce simple text output:

$ docker Inspect--format= ' {{range $p, $conf: =. Networksettings.ports} {{$p}}}-> {{(index $conf 0). Hostport} {{end}} ' $INSTANCE _id
Find a specific port mapping

The. Field syntax doesn ' t work when the field name begins with a number, but the template language ' s index function does. The. Networksettings.ports section contains a map of the internal port mappings to a list of external address/port. To grab just the "Numeric public port", use index to find the specific port map, and then index 0 contains the ECT inside of that. Then We for the "hostport field to get the" public address.

$ docker Inspect--format= ' {{(index. Networksettings.ports "8787/tcp") 0). Hostport} ' $INSTANCE _id
Get a subsection in JSON format

If you request a field which are itself a structure containing other fields, by default and get a go-style dump of the Inne R values. Docker adds a template function, JSON, which can is applied to get results in JSON format.

$ docker Inspect--format= ' {{json. Config}} ' $INSTANCE _id

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.