fix inspect format result

Currently `docker inspect -f` use json.Unmarshal() unmarshal
to interface, it will store all JSON numbers in float64, so
we use `docker inspect 4f0d73b75a0d | grep Memory` and
`docker inspect -f {{.HostConfig.Memory}} 4f0d73b75a0d` will
get different values.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
Qiang Huang
2015-04-23 09:28:07 +08:00
parent cc43263f8c
commit b0ef3194aa
3 changed files with 34 additions and 11 deletions
+7 -2
View File
@@ -57,9 +57,14 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
continue
}
} else {
// Has template, will render
var value interface{}
if err := json.Unmarshal(obj, &value); err != nil {
// Do not use `json.Unmarshal()` because unmarshal JSON into
// an interface value, Unmarshal stores JSON numbers in
// float64, which is different from `json.Indent()` does.
dec := json.NewDecoder(bytes.NewReader(obj))
dec.UseNumber()
if err := dec.Decode(&value); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
status = 1
continue