Ver Fonte

Merge pull request #33940 from yaocaigen/fix_container_multi_names

Fix run `docker rename <container-id> new_name` concurrently, the container will have multi names
Akihiro Suda há 8 anos atrás
pai
commit
8e3555f853
1 ficheiros alterados com 3 adições e 3 exclusões
  1. 3 3
      daemon/rename.go

+ 3 - 3
daemon/rename.go

@@ -32,6 +32,9 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
 		return err
 		return err
 	}
 	}
 
 
+	container.Lock()
+	defer container.Unlock()
+
 	oldName = container.Name
 	oldName = container.Name
 	oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
 	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")
 		return errors.New("Renaming a container with the same name as its current name")
 	}
 	}
 
 
-	container.Lock()
-	defer container.Unlock()
-
 	links := map[string]*dockercontainer.Container{}
 	links := map[string]*dockercontainer.Container{}
 	for k, v := range daemon.linkIndex.children(container) {
 	for k, v := range daemon.linkIndex.children(container) {
 		if !strings.HasPrefix(k, oldName) {
 		if !strings.HasPrefix(k, oldName) {