github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/docs/reference/commandline/inspect.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "inspect"
     4  description = "The inspect command description and usage"
     5  keywords = ["inspect, container, json"]
     6  [menu.main]
     7  parent = "smn_cli"
     8  weight=1
     9  +++
    10  <![end-metadata]-->
    11  
    12  # inspect
    13  
    14      Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
    15  
    16      Return low-level information on a container or image
    17  
    18        -f, --format=""    Format the output using the given go template
    19  
    20  By default, this will render all results in a JSON array. If a format is
    21  specified, the given template will be executed for each result.
    22  
    23  Go's [text/template](http://golang.org/pkg/text/template/) package
    24  describes all the details of the format.
    25  
    26  ## Examples
    27  
    28  **Get an instance's IP address:**
    29  
    30  For the most part, you can pick out any field from the JSON in a fairly
    31  straightforward manner.
    32  
    33      $ docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
    34  
    35  **Get an instance's MAC Address:**
    36  
    37  For the most part, you can pick out any field from the JSON in a fairly
    38  straightforward manner.
    39  
    40      $ docker inspect --format='{{.NetworkSettings.MacAddress}}' $INSTANCE_ID
    41  
    42  **Get an instance's log path:**
    43  
    44      $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
    45  
    46  **List All Port Bindings:**
    47  
    48  One can loop over arrays and maps in the results to produce simple text
    49  output:
    50  
    51      $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
    52  
    53  **Find a Specific Port Mapping:**
    54  
    55  The `.Field` syntax doesn't work when the field name begins with a
    56  number, but the template language's `index` function does. The
    57  `.NetworkSettings.Ports` section contains a map of the internal port
    58  mappings to a list of external address/port objects, so to grab just the
    59  numeric public port, you use `index` to find the specific port map, and
    60  then `index` 0 contains the first object inside of that. Then we ask for
    61  the `HostPort` field to get the public address.
    62  
    63      $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
    64  
    65  **Get config:**
    66  
    67  The `.Field` syntax doesn't work when the field contains JSON data, but
    68  the template language's custom `json` function does. The `.config`
    69  section contains complex JSON object, so to grab it as JSON, you use
    70  `json` to convert the configuration object into JSON.
    71  
    72      $ docker inspect --format='{{json .config}}' $INSTANCE_ID
    73