mirror of https://github.com/docker/docs.git
Implement docker remove with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
b7de53634c
commit
fb6533e6cf
|
@ -0,0 +1,30 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
|
// ContainerRemoveOptions holds parameters to remove containers.
|
||||||
|
type ContainerRemoveOptions struct {
|
||||||
|
ContainerID string
|
||||||
|
RemoveVolumes bool
|
||||||
|
RemoveLinks bool
|
||||||
|
Force bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContainerRemove kills and removes a container from the docker host.
|
||||||
|
func (cli *Client) ContainerRemove(options ContainerRemoveOptions) error {
|
||||||
|
var query url.Values
|
||||||
|
if options.RemoveVolumes {
|
||||||
|
query.Set("v", "1")
|
||||||
|
}
|
||||||
|
if options.RemoveLinks {
|
||||||
|
query.Set("link", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Force {
|
||||||
|
query.Set("force", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := cli.DELETE("/containers/"+options.ContainerID, query, nil)
|
||||||
|
ensureReaderClosed(resp)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -2,9 +2,9 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/client/lib"
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
)
|
)
|
||||||
|
@ -21,18 +21,6 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
|
||||||
val := url.Values{}
|
|
||||||
if *v {
|
|
||||||
val.Set("v", "1")
|
|
||||||
}
|
|
||||||
if *link {
|
|
||||||
val.Set("link", "1")
|
|
||||||
}
|
|
||||||
|
|
||||||
if *force {
|
|
||||||
val.Set("force", "1")
|
|
||||||
}
|
|
||||||
|
|
||||||
var errNames []string
|
var errNames []string
|
||||||
for _, name := range cmd.Args() {
|
for _, name := range cmd.Args() {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
|
@ -40,8 +28,14 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
||||||
}
|
}
|
||||||
name = strings.Trim(name, "/")
|
name = strings.Trim(name, "/")
|
||||||
|
|
||||||
_, _, err := readBody(cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil, nil))
|
options := lib.ContainerRemoveOptions{
|
||||||
if err != nil {
|
ContainerID: name,
|
||||||
|
RemoveVolumes: *v,
|
||||||
|
RemoveLinks: *link,
|
||||||
|
Force: *force,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cli.client.ContainerRemove(options); err != nil {
|
||||||
fmt.Fprintf(cli.err, "%s\n", err)
|
fmt.Fprintf(cli.err, "%s\n", err)
|
||||||
errNames = append(errNames, name)
|
errNames = append(errNames, name)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue