From 4bc28f4e6bb38ec70fb98a4deea723a2d0812d98 Mon Sep 17 00:00:00 2001 From: unclejack Date: Tue, 4 Nov 2014 15:43:58 +0200 Subject: [PATCH] daemon/container: stream & decode JSON Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) --- daemon/container.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index a972f8b712..da5745650c 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -102,13 +102,17 @@ func (container *Container) FromDisk() error { return err } - data, err := ioutil.ReadFile(pth) + jsonSource, err := os.Open(pth) if err != nil { return err } + defer jsonSource.Close() + + dec := json.NewDecoder(jsonSource) + // Load container settings // udp broke compat of docker.PortMapping, but it's not used when loading a container, we can skip it - if err := json.Unmarshal(data, container); err != nil && !strings.Contains(err.Error(), "docker.PortMapping") { + if err := dec.Decode(container); err != nil && !strings.Contains(err.Error(), "docker.PortMapping") { return err }