mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #4385 from khia/json_format
Support json output in --format flag of docker inspect
This commit is contained in:
commit
37d0ce42c6
2 changed files with 21 additions and 1 deletions
|
@ -37,6 +37,13 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"json": func(v interface{}) string {
|
||||
a, _ := json.Marshal(v)
|
||||
return string(a)
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
ErrConnectionRefused = errors.New("Can't connect to docker daemon. Is 'docker -d' running on this host?")
|
||||
)
|
||||
|
@ -640,7 +647,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
|
|||
var tmpl *template.Template
|
||||
if *tmplStr != "" {
|
||||
var err error
|
||||
if tmpl, err = template.New("").Parse(*tmplStr); err != nil {
|
||||
if tmpl, err = template.New("").Funcs(funcMap).Parse(*tmplStr); err != nil {
|
||||
fmt.Fprintf(cli.err, "Template parsing error: %v\n", err)
|
||||
return &utils.StatusError{StatusCode: 64,
|
||||
Status: "Template parsing error: " + err.Error()}
|
||||
|
|
|
@ -809,6 +809,19 @@ we ask for the ``HostPort`` field to get the public address.
|
|||
|
||||
$ sudo docker inspect -format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
||||
|
||||
Get config
|
||||
..........
|
||||
|
||||
The ``.Field`` syntax doesn't work when the field contains JSON data,
|
||||
but the template language's custom ``json`` function does. The ``.config``
|
||||
section contains complex json object, so to grab it as JSON, you use ``json``
|
||||
to convert config object into JSON
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo docker inspect -format='{{json .config}}' $INSTANCE_ID
|
||||
|
||||
|
||||
.. _cli_kill:
|
||||
|
||||
``kill``
|
||||
|
|
Loading…
Reference in a new issue