github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/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 one or multiple containers, images, volumes,
    22  networks, nodes, services, or tasks 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                       values are "image" or "container" or "task
    29        --type         Return JSON for specified type
    30  ```
    31  
    32  By default, this will render all results in a JSON array. If the container and
    33  image have the same name, this will return container JSON for unspecified type.
    34  If a format is specified, the given template will be executed for each result.
    35  
    36  Go's [text/template](http://golang.org/pkg/text/template/) package
    37  describes all the details of the format.
    38  
    39  ## Examples
    40  
    41  **Get an instance's IP address:**
    42  
    43  For the most part, you can pick out any field from the JSON in a fairly
    44  straightforward manner.
    45  
    46      {% raw %}
    47      $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
    48      {% endraw %}
    49  
    50  **Get an instance's MAC address:**
    51  
    52  For the most part, you can pick out any field from the JSON in a fairly
    53  straightforward manner.
    54  
    55      {% raw %}
    56      $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
    57      {% endraw %}
    58  
    59  **Get an instance's log path:**
    60  
    61      {% raw %}
    62      $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
    63      {% endraw %}
    64  
    65  **Get a Task's image name:**
    66  
    67      {% raw %}
    68      $ docker inspect --format='{{.Container.Spec.Image}}' $INSTANCE_ID
    69      {% endraw %}
    70  
    71  **List all port bindings:**
    72  
    73  One can loop over arrays and maps in the results to produce simple text
    74  output:
    75  
    76      {% raw %}
    77      $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
    78      {% endraw %}
    79  
    80  **Find a specific port mapping:**
    81  
    82  The `.Field` syntax doesn't work when the field name begins with a
    83  number, but the template language's `index` function does. The
    84  `.NetworkSettings.Ports` section contains a map of the internal port
    85  mappings to a list of external address/port objects. To grab just the
    86  numeric public port, you use `index` to find the specific port map, and
    87  then `index` 0 contains the first object inside of that. Then we ask for
    88  the `HostPort` field to get the public address.
    89  
    90      {% raw %}
    91      $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
    92      {% endraw %}
    93  
    94  **Get a subsection in JSON format:**
    95  
    96  If you request a field which is itself a structure containing other
    97  fields, by default you get a Go-style dump of the inner values.
    98  Docker adds a template function, `json`, which can be applied to get
    99  results in JSON format.
   100  
   101      {% raw %}
   102      $ docker inspect --format='{{json .Config}}' $INSTANCE_ID
   103      {% endraw %}