diff --git a/daemon/rename.go b/daemon/rename.go index ad21593c19..2a8d0b22c7 100644 --- a/daemon/rename.go +++ b/daemon/rename.go @@ -32,6 +32,9 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error { return err } + container.Lock() + defer container.Unlock() + oldName = container.Name oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint @@ -39,9 +42,6 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error { return errors.New("Renaming a container with the same name as its current name") } - container.Lock() - defer container.Unlock() - links := map[string]*dockercontainer.Container{} for k, v := range daemon.linkIndex.children(container) { if !strings.HasPrefix(k, oldName) {