Signed-off-by: David Calavera <david.calavera@gmail.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,12 @@ |
| 0 |
+package lib |
|
| 1 |
+ |
|
| 2 |
+import "net/url" |
|
| 3 |
+ |
|
| 4 |
+// ContainerRename changes the name of a given container. |
|
| 5 |
+func (cli *Client) ContainerRename(containerID, newContainerName string) error {
|
|
| 6 |
+ var query url.Values |
|
| 7 |
+ query.Set("name", newContainerName)
|
|
| 8 |
+ resp, err := cli.POST("/containers/"+containerID+"/rename", query, nil, nil)
|
|
| 9 |
+ ensureReaderClosed(resp) |
|
| 10 |
+ return err |
|
| 11 |
+} |
| ... | ... |
@@ -24,7 +24,7 @@ func (cli *DockerCli) CmdRename(args ...string) error {
|
| 24 | 24 |
return fmt.Errorf("Error: Neither old nor new names may be empty")
|
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 |
- if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
|
|
| 27 |
+ if err := cli.client.ContainerRename(oldName, newName); err != nil {
|
|
| 28 | 28 |
fmt.Fprintf(cli.err, "%s\n", err) |
| 29 | 29 |
return fmt.Errorf("Error: failed to rename container named %s", oldName)
|
| 30 | 30 |
} |