1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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)
This commit is contained in:
Solomon Hykes 2014-02-11 17:59:45 -08:00
parent 567a422a65
commit 44e10433c7
3 changed files with 21 additions and 2 deletions

View file

@ -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
api/container.go Normal file
View file

@ -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
}
}

View file

@ -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"