github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/docs/reference/commandline/inspect.md (about)

     1  ---
     2  title: "inspect"
     3  description: "The inspect command description and usage"
     4  keywords: "inspect, container, json"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # inspect
    17  
    18  ```markdown
    19  Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]
    20  
    21  Return low-level information on Docker object(s) (e.g. container, image, volume,
    22  network, node, service, or task) identified by name or ID
    23  
    24  Options:
    25    -f, --format       Format the output using the given Go template
    26        --help         Print usage
    27    -s, --size         Display total file sizes if the type is container
    28        --type         Return JSON for specified type
    29  ```
    30  
    31  ## Description
    32  
    33  By default, `docker inspect` will render all results in a JSON array. If the container and
    34  image have the same name, this will return container JSON for unspecified type.
    35  If a format is specified, the given template will be executed for each result.
    36  
    37  Go's [text/template](http://golang.org/pkg/text/template/) package
    38  describes all the details of the format.
    39  
    40  ## Examples
    41  
    42  ### Get an instance's IP address
    43  
    44  For the most part, you can pick out any field from the JSON in a fairly
    45  straightforward manner.
    46  
    47  ```bash
    48  {% raw %}
    49  $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
    50  {% endraw %}
    51  ```
    52  
    53  ### Get an instance's MAC address
    54  
    55  ```bash
    56  {% raw %}
    57  $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
    58  {% endraw %}
    59  ```
    60  
    61  ### Get an instance's log path
    62  
    63  ```bash
    64  {% raw %}
    65  $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
    66  {% endraw %}
    67  ```
    68  
    69  ### Get an instance's image name
    70  
    71  ```bash
    72  {% raw %}
    73  $ docker inspect --format='{{.Container.Spec.Image}}' $INSTANCE_ID
    74  {% endraw %}
    75  ```
    76  
    77  ### List all port bindings
    78  
    79  You can loop over arrays and maps in the results to produce simple text
    80  output:
    81  
    82  ```bash
    83  {% raw %}
    84  $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
    85  {% endraw %}
    86  ```
    87  
    88  ### Find a specific port mapping
    89  
    90  The `.Field` syntax doesn't work when the field name begins with a
    91  number, but the template language's `index` function does. The
    92  `.NetworkSettings.Ports` section contains a map of the internal port
    93  mappings to a list of external address/port objects. To grab just the
    94  numeric public port, you use `index` to find the specific port map, and
    95  then `index` 0 contains the first object inside of that. Then we ask for
    96  the `HostPort` field to get the public address.
    97  
    98  ```bash
    99  {% raw %}
   100  $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
   101  {% endraw %}
   102  ```
   103  
   104  ### Get a subsection in JSON format
   105  
   106  If you request a field which is itself a structure containing other
   107  fields, by default you get a Go-style dump of the inner values.
   108  Docker adds a template function, `json`, which can be applied to get
   109  results in JSON format.
   110  
   111  ```bash
   112  {% raw %}
   113  $ docker inspect --format='{{json .Config}}' $INSTANCE_ID
   114  {% endraw %}
   115  ```