mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement container rename with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
d05aa418b0
commit
ac8fb77c74
2 changed files with 13 additions and 1 deletions
12
api/client/lib/container_rename.go
Normal file
12
api/client/lib/container_rename.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
|
// ContainerRename changes the name of a given container.
|
||||||
|
func (cli *Client) ContainerRename(containerID, newContainerName string) error {
|
||||||
|
var query url.Values
|
||||||
|
query.Set("name", newContainerName)
|
||||||
|
resp, err := cli.POST("/containers/"+containerID+"/rename", query, nil, nil)
|
||||||
|
ensureReaderClosed(resp)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ func (cli *DockerCli) CmdRename(args ...string) error {
|
||||||
return fmt.Errorf("Error: Neither old nor new names may be empty")
|
return fmt.Errorf("Error: Neither old nor new names may be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
|
if err := cli.client.ContainerRename(oldName, newName); err != nil {
|
||||||
fmt.Fprintf(cli.err, "%s\n", err)
|
fmt.Fprintf(cli.err, "%s\n", err)
|
||||||
return fmt.Errorf("Error: failed to rename container named %s", oldName)
|
return fmt.Errorf("Error: failed to rename container named %s", oldName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue