mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
089166ebe2
commit
be072a8954
2 changed files with 24 additions and 0 deletions
|
@ -27,6 +27,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
oldName = container.Name
|
oldName = container.Name
|
||||||
|
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
|
||||||
|
|
||||||
container.Lock()
|
container.Lock()
|
||||||
defer container.Unlock()
|
defer container.Unlock()
|
||||||
|
@ -35,10 +36,12 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.Name = newName
|
container.Name = newName
|
||||||
|
container.NetworkSettings.IsAnonymousEndpoint = false
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
container.Name = oldName
|
container.Name = oldName
|
||||||
|
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
|
||||||
daemon.reserveName(container.ID, oldName)
|
daemon.reserveName(container.ID, oldName)
|
||||||
daemon.releaseName(newName)
|
daemon.releaseName(newName)
|
||||||
}
|
}
|
||||||
|
@ -61,6 +64,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
container.Name = oldName
|
container.Name = oldName
|
||||||
|
container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint
|
||||||
if e := container.ToDisk(); e != nil {
|
if e := container.ToDisk(); e != nil {
|
||||||
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
|
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")
|
out, _ = dockerCmd(c, "ps", "-a")
|
||||||
c.Assert(out, checker.Contains, "myname", check.Commentf("Output of docker ps should have included 'myname': %s", out))
|
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…
Add table
Reference in a new issue