Merge pull request #22716 from jmzwcn/issue22466-patches
Embedded DNS problem after renaming container. Step2:change in docker…
This commit is contained in:
commit
4441a6c4c6
2 changed files with 24 additions and 0 deletions
|
@ -27,6 +27,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
|||
}
|
||||
|
||||
oldName = container.Name
|
||||
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
|
||||
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
@ -35,10 +36,12 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
|||
}
|
||||
|
||||
container.Name = newName
|
||||
container.NetworkSettings.IsAnonymousEndpoint = false
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
container.Name = oldName
|
||||
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
|
||||
daemon.reserveName(container.ID, oldName)
|
||||
daemon.releaseName(newName)
|
||||
}
|
||||
|
@ -61,6 +64,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
|||
defer func() {
|
||||
if err != nil {
|
||||
container.Name = oldName
|
||||
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
|
||||
if e := container.ToDisk(); e != nil {
|
||||
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
|
||||
}
|
||||
|
|
|
@ -84,3 +84,23 @@ func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
|||
out, _ = dockerCmd(c, "ps", "-a")
|
||||
c.Assert(out, checker.Contains, "myname", check.Commentf("Output of docker ps should have included 'myname': %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRenameAnonymousContainer(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
dockerCmd(c, "network", "create", "network1")
|
||||
out, _ := dockerCmd(c, "create", "-it", "--net", "network1", "busybox", "top")
|
||||
|
||||
anonymousContainerID := strings.TrimSpace(out)
|
||||
|
||||
dockerCmd(c, "rename", anonymousContainerID, "container1")
|
||||
dockerCmd(c, "start", "container1")
|
||||
|
||||
count := "-c"
|
||||
if daemonPlatform == "windows" {
|
||||
count = "-n"
|
||||
}
|
||||
|
||||
_, _, err := dockerCmdWithError("run", "--net", "network1", "busybox", "ping", count, "1", "container1")
|
||||
c.Assert(err, check.IsNil, check.Commentf("Embedded DNS lookup fails after renaming anonymous container: %v", err))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue