github.com/yogeshlonkar/moby@v1.13.2-0.20201203103638-c0b64beaea94/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  $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
    49  ```
    50  
    51  ### Get an instance's MAC address
    52  
    53  ```bash
    54  $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
    55  ```
    56  
    57  ### Get an instance's log path
    58  
    59  ```bash
    60  $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
    61  ```
    62  
    63  ### Get an instance's image name
    64  
    65  ```bash
    66  $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
    67  ```
    68  
    69  ### List all port bindings
    70  
    71  You can loop over arrays and maps in the results to produce simple text
    72  output:
    73  
    74  ```bash
    75  $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
    76  ```
    77  
    78  ### Find a specific port mapping
    79  
    80  The `.Field` syntax doesn't work when the field name begins with a
    81  number, but the template language's `index` function does. The
    82  `.NetworkSettings.Ports` section contains a map of the internal port
    83  mappings to a list of external address/port objects. To grab just the
    84  numeric public port, you use `index` to find the specific port map, and
    85  then `index` 0 contains the first object inside of that. Then we ask for
    86  the `HostPort` field to get the public address.
    87  
    88  ```bash
    89  $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
    90  ```
    91  
    92  ### Get a subsection in JSON format
    93  
    94  If you request a field which is itself a structure containing other
    95  fields, by default you get a Go-style dump of the inner values.
    96  Docker adds a template function, `json`, which can be applied to get
    97  results in JSON format.
    98  
    99  ```bash
   100  $ docker inspect --format='{{json .Config}}' $INSTANCE_ID
   101  ```