Browse Source

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 <solomon@docker.com> (github: shykes)
Solomon Hykes 11 years ago
parent
commit
44e10433c7
3 changed files with 21 additions and 2 deletions
  1. 2 2
      api/client.go
  2. 18 0
      api/container.go
  3. 1 0
      docker/docker.go

+ 2 - 2
api/client.go

@@ -1572,7 +1572,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
 		return err
 		return err
 	}
 	}
 
 
-	if !container.State.IsRunning() {
+	if !container.State.Running {
 		return fmt.Errorf("Impossible to attach to a stopped container, start it first")
 		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 {
 	if err := json.Unmarshal(body, c); err != nil {
 		return false, -1, err
 		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) {
 func readBody(stream io.ReadCloser, statusCode int, err error) ([]byte, int, error) {

+ 18 - 0
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
+	}
+}

+ 1 - 0
docker/docker.go

@@ -6,6 +6,7 @@ import (
 	"os"
 	"os"
 	"strings"
 	"strings"
 
 
+	_ "github.com/dotcloud/docker"
 	"github.com/dotcloud/docker/api"
 	"github.com/dotcloud/docker/api"
 	"github.com/dotcloud/docker/dockerversion"
 	"github.com/dotcloud/docker/dockerversion"
 	"github.com/dotcloud/docker/engine"
 	"github.com/dotcloud/docker/engine"