mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #11326 from cpuguy83/11315_rename_w_daemon_restart
Persist container to disk after rename
This commit is contained in:
commit
c6321931d2
2 changed files with 39 additions and 3 deletions
|
@ -1,8 +1,6 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/engine"
|
||||
)
|
||||
import "github.com/docker/docker/engine"
|
||||
|
||||
func (daemon *Daemon) ContainerRename(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 {
|
||||
|
@ -26,9 +24,21 @@ func (daemon *Daemon) ContainerRename(job *engine.Job) engine.Status {
|
|||
|
||||
container.Name = newName
|
||||
|
||||
undo := func() {
|
||||
container.Name = oldName
|
||||
daemon.reserveName(container.ID, oldName)
|
||||
daemon.containerGraph.Delete(newName)
|
||||
}
|
||||
|
||||
if err := daemon.containerGraph.Delete(oldName); err != nil {
|
||||
undo()
|
||||
return job.Errorf("Failed to delete container %q: %v", oldName, err)
|
||||
}
|
||||
|
||||
if err := container.toDisk(); err != nil {
|
||||
undo()
|
||||
return job.Error(err)
|
||||
}
|
||||
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
|
|
@ -534,3 +534,29 @@ func TestDaemonUlimitDefaults(t *testing.T) {
|
|||
|
||||
logDone("daemon - default ulimits are applied")
|
||||
}
|
||||
|
||||
// #11315
|
||||
func TestDaemonRestartRenameContainer(t *testing.T) {
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if out, err := d.Cmd("run", "--name=test", "busybox"); err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
if out, err := d.Cmd("rename", "test", "test2"); err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
if err := d.Restart(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if out, err := d.Cmd("start", "test2"); err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
logDone("daemon - rename persists through daemon restart")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue