Merge pull request #11326 from cpuguy83/11315_rename_w_daemon_restart

Persist container to disk after rename
This commit is contained in:
Jessie Frazelle 2015-03-11 13:44:13 -07:00
Родитель bf35122890 c5c72cf151
Коммит c6321931d2
2 изменённых файлов: 39 добавлений и 3 удалений

Просмотреть файл

@ -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")
}