|
@@ -26,7 +26,7 @@ import (
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
log "github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/api"
|
|
"github.com/docker/docker/api"
|
|
- "github.com/docker/docker/api/stats"
|
|
|
|
|
|
+ "github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/autogen/dockerversion"
|
|
"github.com/docker/docker/autogen/dockerversion"
|
|
"github.com/docker/docker/engine"
|
|
"github.com/docker/docker/engine"
|
|
"github.com/docker/docker/graph"
|
|
"github.com/docker/docker/graph"
|
|
@@ -2133,7 +2133,7 @@ func (cid *cidFile) Write(id string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runconfig.HostConfig, cidfile, name string) (engine.Env, error) {
|
|
|
|
|
|
+func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runconfig.HostConfig, cidfile, name string) (*types.ContainerCreateResponse, error) {
|
|
containerValues := url.Values{}
|
|
containerValues := url.Values{}
|
|
if name != "" {
|
|
if name != "" {
|
|
containerValues.Set("name", name)
|
|
containerValues.Set("name", name)
|
|
@@ -2172,23 +2172,19 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- var result engine.Env
|
|
|
|
- if err := result.Decode(stream); err != nil {
|
|
|
|
|
|
+ var response types.ContainerCreateResponse
|
|
|
|
+ if err := json.NewDecoder(stream).Decode(&response); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
-
|
|
|
|
- for _, warning := range result.GetList("Warnings") {
|
|
|
|
|
|
+ for _, warning := range response.Warnings {
|
|
fmt.Fprintf(cli.err, "WARNING: %s\n", warning)
|
|
fmt.Fprintf(cli.err, "WARNING: %s\n", warning)
|
|
}
|
|
}
|
|
-
|
|
|
|
if containerIDFile != nil {
|
|
if containerIDFile != nil {
|
|
- if err = containerIDFile.Write(result.Get("Id")); err != nil {
|
|
|
|
|
|
+ if err = containerIDFile.Write(response.ID); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- return result, nil
|
|
|
|
-
|
|
|
|
|
|
+ return &response, nil
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) CmdCreate(args ...string) error {
|
|
func (cli *DockerCli) CmdCreate(args ...string) error {
|
|
@@ -2207,14 +2203,11 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
|
|
cmd.Usage()
|
|
cmd.Usage()
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
-
|
|
|
|
- createResult, err := cli.createContainer(config, hostConfig, hostConfig.ContainerIDFile, *flName)
|
|
|
|
|
|
+ response, err := cli.createContainer(config, hostConfig, hostConfig.ContainerIDFile, *flName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
- fmt.Fprintf(cli.out, "%s\n", createResult.Get("Id"))
|
|
|
|
-
|
|
|
|
|
|
+ fmt.Fprintf(cli.out, "%s\n", response.ID)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2272,38 +2265,32 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
sigProxy = false
|
|
sigProxy = false
|
|
}
|
|
}
|
|
|
|
|
|
- runResult, err := cli.createContainer(config, hostConfig, hostConfig.ContainerIDFile, *flName)
|
|
|
|
|
|
+ createResponse, err := cli.createContainer(config, hostConfig, hostConfig.ContainerIDFile, *flName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
if sigProxy {
|
|
if sigProxy {
|
|
- sigc := cli.forwardAllSignals(runResult.Get("Id"))
|
|
|
|
|
|
+ sigc := cli.forwardAllSignals(createResponse.ID)
|
|
defer signal.StopCatch(sigc)
|
|
defer signal.StopCatch(sigc)
|
|
}
|
|
}
|
|
-
|
|
|
|
var (
|
|
var (
|
|
waitDisplayId chan struct{}
|
|
waitDisplayId chan struct{}
|
|
errCh chan error
|
|
errCh chan error
|
|
)
|
|
)
|
|
-
|
|
|
|
if !config.AttachStdout && !config.AttachStderr {
|
|
if !config.AttachStdout && !config.AttachStderr {
|
|
// Make this asynchronous to allow the client to write to stdin before having to read the ID
|
|
// Make this asynchronous to allow the client to write to stdin before having to read the ID
|
|
waitDisplayId = make(chan struct{})
|
|
waitDisplayId = make(chan struct{})
|
|
go func() {
|
|
go func() {
|
|
defer close(waitDisplayId)
|
|
defer close(waitDisplayId)
|
|
- fmt.Fprintf(cli.out, "%s\n", runResult.Get("Id"))
|
|
|
|
|
|
+ fmt.Fprintf(cli.out, "%s\n", createResponse.ID)
|
|
}()
|
|
}()
|
|
}
|
|
}
|
|
-
|
|
|
|
if *flAutoRemove && (hostConfig.RestartPolicy.Name == "always" || hostConfig.RestartPolicy.Name == "on-failure") {
|
|
if *flAutoRemove && (hostConfig.RestartPolicy.Name == "always" || hostConfig.RestartPolicy.Name == "on-failure") {
|
|
return ErrConflictRestartPolicyAndAutoRemove
|
|
return ErrConflictRestartPolicyAndAutoRemove
|
|
}
|
|
}
|
|
-
|
|
|
|
// We need to instantiate the chan because the select needs it. It can
|
|
// We need to instantiate the chan because the select needs it. It can
|
|
// be closed but can't be uninitialized.
|
|
// be closed but can't be uninitialized.
|
|
hijacked := make(chan io.Closer)
|
|
hijacked := make(chan io.Closer)
|
|
-
|
|
|
|
// Block the return until the chan gets closed
|
|
// Block the return until the chan gets closed
|
|
defer func() {
|
|
defer func() {
|
|
log.Debugf("End of CmdRun(), Waiting for hijack to finish.")
|
|
log.Debugf("End of CmdRun(), Waiting for hijack to finish.")
|
|
@@ -2311,7 +2298,6 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
log.Errorf("Hijack did not finish (chan still open)")
|
|
log.Errorf("Hijack did not finish (chan still open)")
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
-
|
|
|
|
if config.AttachStdin || config.AttachStdout || config.AttachStderr {
|
|
if config.AttachStdin || config.AttachStdout || config.AttachStderr {
|
|
var (
|
|
var (
|
|
out, stderr io.Writer
|
|
out, stderr io.Writer
|
|
@@ -2319,7 +2305,6 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
v = url.Values{}
|
|
v = url.Values{}
|
|
)
|
|
)
|
|
v.Set("stream", "1")
|
|
v.Set("stream", "1")
|
|
-
|
|
|
|
if config.AttachStdin {
|
|
if config.AttachStdin {
|
|
v.Set("stdin", "1")
|
|
v.Set("stdin", "1")
|
|
in = cli.in
|
|
in = cli.in
|
|
@@ -2336,14 +2321,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
stderr = cli.err
|
|
stderr = cli.err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
errCh = promise.Go(func() error {
|
|
errCh = promise.Go(func() error {
|
|
- return cli.hijack("POST", "/containers/"+runResult.Get("Id")+"/attach?"+v.Encode(), config.Tty, in, out, stderr, hijacked, nil)
|
|
|
|
|
|
+ return cli.hijack("POST", "/containers/"+createResponse.ID+"/attach?"+v.Encode(), config.Tty, in, out, stderr, hijacked, nil)
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
close(hijacked)
|
|
close(hijacked)
|
|
}
|
|
}
|
|
-
|
|
|
|
// Acknowledge the hijack before starting
|
|
// Acknowledge the hijack before starting
|
|
select {
|
|
select {
|
|
case closer := <-hijacked:
|
|
case closer := <-hijacked:
|
|
@@ -2360,12 +2343,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
//start the container
|
|
//start the container
|
|
- if _, _, err = readBody(cli.call("POST", "/containers/"+runResult.Get("Id")+"/start", nil, false)); err != nil {
|
|
|
|
|
|
+ if _, _, err = readBody(cli.call("POST", "/containers/"+createResponse.ID+"/start", nil, false)); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && cli.isTerminalOut {
|
|
if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && cli.isTerminalOut {
|
|
- if err := cli.monitorTtySize(runResult.Get("Id"), false); err != nil {
|
|
|
|
|
|
+ if err := cli.monitorTtySize(createResponse.ID, false); err != nil {
|
|
log.Errorf("Error monitoring TTY size: %s", err)
|
|
log.Errorf("Error monitoring TTY size: %s", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2390,26 +2373,26 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
if *flAutoRemove {
|
|
if *flAutoRemove {
|
|
// Autoremove: wait for the container to finish, retrieve
|
|
// Autoremove: wait for the container to finish, retrieve
|
|
// the exit code and remove the container
|
|
// the exit code and remove the container
|
|
- if _, _, err := readBody(cli.call("POST", "/containers/"+runResult.Get("Id")+"/wait", nil, false)); err != nil {
|
|
|
|
|
|
+ if _, _, err := readBody(cli.call("POST", "/containers/"+createResponse.ID+"/wait", nil, false)); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if _, status, err = getExitCode(cli, runResult.Get("Id")); err != nil {
|
|
|
|
|
|
+ if _, status, err = getExitCode(cli, createResponse.ID); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if _, _, err := readBody(cli.call("DELETE", "/containers/"+runResult.Get("Id")+"?v=1", nil, false)); err != nil {
|
|
|
|
|
|
+ if _, _, err := readBody(cli.call("DELETE", "/containers/"+createResponse.ID+"?v=1", nil, false)); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// No Autoremove: Simply retrieve the exit code
|
|
// No Autoremove: Simply retrieve the exit code
|
|
if !config.Tty {
|
|
if !config.Tty {
|
|
// In non-TTY mode, we can't detach, so we must wait for container exit
|
|
// In non-TTY mode, we can't detach, so we must wait for container exit
|
|
- if status, err = waitForExit(cli, runResult.Get("Id")); err != nil {
|
|
|
|
|
|
+ if status, err = waitForExit(cli, createResponse.ID); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// In TTY mode, there is a race: if the process dies too slowly, the state could
|
|
// In TTY mode, there is a race: if the process dies too slowly, the state could
|
|
// be updated after the getExitCode call and result in the wrong exit code being reported
|
|
// be updated after the getExitCode call and result in the wrong exit code being reported
|
|
- if _, status, err = getExitCode(cli, runResult.Get("Id")); err != nil {
|
|
|
|
|
|
+ if _, status, err = getExitCode(cli, createResponse.ID); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2653,7 +2636,7 @@ func (s *containerStats) Collect(cli *DockerCli) {
|
|
)
|
|
)
|
|
go func() {
|
|
go func() {
|
|
for {
|
|
for {
|
|
- var v *stats.Stats
|
|
|
|
|
|
+ var v *types.Stats
|
|
if err := dec.Decode(&v); err != nil {
|
|
if err := dec.Decode(&v); err != nil {
|
|
u <- err
|
|
u <- err
|
|
return
|
|
return
|
|
@@ -2770,7 +2753,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func calculateCpuPercent(previousCpu, previousSystem uint64, v *stats.Stats) float64 {
|
|
|
|
|
|
+func calculateCpuPercent(previousCpu, previousSystem uint64, v *types.Stats) float64 {
|
|
var (
|
|
var (
|
|
cpuPercent = 0.0
|
|
cpuPercent = 0.0
|
|
// calculate the change for the cpu usage of the container in between readings
|
|
// calculate the change for the cpu usage of the container in between readings
|