From 9c1c314fd97094bf805a25d7aac4e5dae3f05d51 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 11 Feb 2014 17:59:45 -0800 Subject: [PATCH] api/container.go: an API-specific representation of a container This breaks the dependency from the remote API implementation to the internal representation of a container. Instead it uses its own partial representation of a container, with only required fields. * This preserves reverse-compatibility with all past implementations of the remote API. * This clarifies which fields are guaranteed to be present in a response A docker remote api server *may* return more fields in a Container object, but their presence and semantics are not guaranteed and should not be relied upon by client implementations. Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: 44e10433c7a3811d4d0897192418cb6b62996584 Component: engine --- components/engine/api/client.go | 4 ++-- components/engine/api/container.go | 18 ++++++++++++++++++ components/engine/docker/docker.go | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 components/engine/api/container.go diff --git a/components/engine/api/client.go b/components/engine/api/client.go index c724d08269..f1f336d5f4 100644 --- a/components/engine/api/client.go +++ b/components/engine/api/client.go @@ -1572,7 +1572,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error { return err } - if !container.State.IsRunning() { + if !container.State.Running { return fmt.Errorf("Impossible to attach to a stopped container, start it first") } @@ -2355,7 +2355,7 @@ func getExitCode(cli *DockerCli, containerId string) (bool, int, error) { if err := json.Unmarshal(body, c); err != nil { return false, -1, err } - return c.State.IsRunning(), c.State.GetExitCode(), nil + return c.State.Running, c.State.ExitCode, nil } func readBody(stream io.ReadCloser, statusCode int, err error) ([]byte, int, error) { diff --git a/components/engine/api/container.go b/components/engine/api/container.go new file mode 100644 index 0000000000..4cc73b2252 --- /dev/null +++ b/components/engine/api/container.go @@ -0,0 +1,18 @@ +package api + +import ( + "github.com/dotcloud/docker/nat" + "github.com/dotcloud/docker/runconfig" +) + +type Container struct { + Config runconfig.Config + HostConfig runconfig.HostConfig + State struct { + Running bool + ExitCode int + } + NetworkSettings struct { + Ports nat.PortMap + } +} diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 5b0d279a5b..b4d7879397 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -6,6 +6,7 @@ import ( "os" "strings" + _ "github.com/dotcloud/docker" "github.com/dotcloud/docker/api" "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine"