Embedded DNS problem after renaming container. Step2:change in docker/daemon side and add integration test

Signed-off-by: Daniel Zhang <jmzwcn@gmail.com>
This commit is contained in:
Daniel Zhang 2016-05-13 10:45:42 +08:00
parent 089166ebe2
commit be072a8954
2 changed files with 24 additions and 0 deletions

View File

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

View File

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