Signed-off-by: Daniel Zhang <jmzwcn@gmail.com>
| ... | ... |
@@ -27,6 +27,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
oldName = container.Name |
| 30 |
+ oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint |
|
| 30 | 31 |
|
| 31 | 32 |
container.Lock() |
| 32 | 33 |
defer container.Unlock() |
| ... | ... |
@@ -35,10 +36,12 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
container.Name = newName |
| 38 |
+ container.NetworkSettings.IsAnonymousEndpoint = false |
|
| 38 | 39 |
|
| 39 | 40 |
defer func() {
|
| 40 | 41 |
if err != nil {
|
| 41 | 42 |
container.Name = oldName |
| 43 |
+ container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint |
|
| 42 | 44 |
daemon.reserveName(container.ID, oldName) |
| 43 | 45 |
daemon.releaseName(newName) |
| 44 | 46 |
} |
| ... | ... |
@@ -61,6 +64,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
| 61 | 61 |
defer func() {
|
| 62 | 62 |
if err != nil {
|
| 63 | 63 |
container.Name = oldName |
| 64 |
+ container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint |
|
| 64 | 65 |
if e := container.ToDisk(); e != nil {
|
| 65 | 66 |
logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e)
|
| 66 | 67 |
} |
| ... | ... |
@@ -84,3 +84,23 @@ func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
| 84 | 84 |
out, _ = dockerCmd(c, "ps", "-a") |
| 85 | 85 |
c.Assert(out, checker.Contains, "myname", check.Commentf("Output of docker ps should have included 'myname': %s", out))
|
| 86 | 86 |
} |
| 87 |
+ |
|
| 88 |
+func (s *DockerSuite) TestRenameAnonymousContainer(c *check.C) {
|
|
| 89 |
+ testRequires(c, DaemonIsLinux) |
|
| 90 |
+ |
|
| 91 |
+ dockerCmd(c, "network", "create", "network1") |
|
| 92 |
+ out, _ := dockerCmd(c, "create", "-it", "--net", "network1", "busybox", "top") |
|
| 93 |
+ |
|
| 94 |
+ anonymousContainerID := strings.TrimSpace(out) |
|
| 95 |
+ |
|
| 96 |
+ dockerCmd(c, "rename", anonymousContainerID, "container1") |
|
| 97 |
+ dockerCmd(c, "start", "container1") |
|
| 98 |
+ |
|
| 99 |
+ count := "-c" |
|
| 100 |
+ if daemonPlatform == "windows" {
|
|
| 101 |
+ count = "-n" |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ _, _, err := dockerCmdWithError("run", "--net", "network1", "busybox", "ping", count, "1", "container1")
|
|
| 105 |
+ c.Assert(err, check.IsNil, check.Commentf("Embedded DNS lookup fails after renaming anonymous container: %v", err))
|
|
| 106 |
+} |