Implement docker stop with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-12-04 13:38:31 -05:00
parent 373f55eecd
commit 9ec1cf92f5
2 changed files with 17 additions and 7 deletions

View File

@ -0,0 +1,16 @@
package lib
import (
"net/url"
"strconv"
)
// ContainerStop stops a container without terminating the process.
// The process is blocked until the container stops or the timeout expires.
func (cli *Client) ContainerStop(containerID string, timeout int) error {
var query url.Values
query.Set("t", strconv.Itoa(timeout))
resp, err := cli.POST("/containers/"+containerID+"/stop", query, nil, nil)
ensureReaderClosed(resp)
return err
}

View File

@ -2,8 +2,6 @@ package client
import (
"fmt"
"net/url"
"strconv"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
@ -21,13 +19,9 @@ func (cli *DockerCli) CmdStop(args ...string) error {
cmd.ParseFlags(args, true)
v := url.Values{}
v.Set("t", strconv.Itoa(*nSeconds))
var errNames []string
for _, name := range cmd.Args() {
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil, nil))
if err != nil {
if err := cli.client.ContainerStop(name, *nSeconds); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
errNames = append(errNames, name)
} else {