rename a existing container
Closes #3036 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com> Upstream-commit: 21a809d9ae0ef8392f37c9262dca93ff31966e22 Component: engine
This commit is contained in:
committed by
Srini Brahmaroutu
parent
6a864dec5f
commit
eacdfc7d44
@@ -113,6 +113,7 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
||||
"commit": daemon.ContainerCommit,
|
||||
"container_changes": daemon.ContainerChanges,
|
||||
"container_copy": daemon.ContainerCopy,
|
||||
"container_rename": daemon.ContainerRename,
|
||||
"container_inspect": daemon.ContainerInspect,
|
||||
"containers": daemon.Containers,
|
||||
"create": daemon.ContainerCreate,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/engine"
|
||||
)
|
||||
|
||||
func (daemon *Daemon) ContainerRename(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 {
|
||||
return job.Errorf("usage: %s OLD_NAME NEW_NAME", job.Name)
|
||||
}
|
||||
old_name := job.Args[0]
|
||||
new_name := job.Args[1]
|
||||
|
||||
container := daemon.Get(old_name)
|
||||
if container == nil {
|
||||
return job.Errorf("No such container: %s", old_name)
|
||||
}
|
||||
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
if err := daemon.containerGraph.Delete(container.Name); err != nil {
|
||||
return job.Errorf("Failed to delete container %q: %v", old_name, err)
|
||||
}
|
||||
if _, err := daemon.reserveName(container.ID, new_name); err != nil {
|
||||
return job.Errorf("Error when allocating new name: %s", err)
|
||||
}
|
||||
container.Name = new_name
|
||||
|
||||
return engine.StatusOK
|
||||
}
|
||||
Reference in New Issue
Block a user