From 51db855bc309458f96158fbfc5e3ad6e3f94bb83 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 2 Oct 2013 10:02:45 -0700 Subject: [PATCH] Remove network connection when link is removed --- commands.go | 4 ++-- container.go | 2 +- server.go | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/commands.go b/commands.go index 0639f65ba..28985b107 100644 --- a/commands.go +++ b/commands.go @@ -762,8 +762,8 @@ func (cli *DockerCli) CmdRm(args ...string) error { val.Set("link", "1") } for _, name := range cmd.Args() { - name = cleanName(name) - _, _, err := cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil) + encName := cleanName(name) + _, _, err := cli.call("DELETE", "/containers/"+encName+"?"+val.Encode(), nil) if err != nil { fmt.Fprintf(cli.err, "%s\n", err) } else { diff --git a/container.go b/container.go index e9b5380cd..55f0096fa 100644 --- a/container.go +++ b/container.go @@ -859,7 +859,7 @@ func (container *Container) Start(hostConfig *HostConfig) error { return err } - container.activeLinks[p] = link + container.activeLinks[link.Alias()] = link if err := link.Enable(); err != nil { rollback() return err diff --git a/server.go b/server.go index a708376c3..0fe6673ea 100644 --- a/server.go +++ b/server.go @@ -964,12 +964,24 @@ func (srv *Server) ContainerRestart(name string, t int) error { func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool) error { if removeLink { - parent, _ := path.Split(name) - p := srv.runtime.containerGraph.Get(parent) - parentContainer := srv.runtime.Get(p.ID()) + p := name + if p[0] != '/' { + p = "/" + p + } + parent, n := path.Split(p) + l := len(parent) + if parent[l-1] == '/' { + parent = parent[:l-1] + } + + pe := srv.runtime.containerGraph.Get(parent) + parentContainer := srv.runtime.Get(pe.ID()) + if parentContainer != nil && parentContainer.activeLinks != nil { - if link, exists := parentContainer.activeLinks[name]; exists { + if link, exists := parentContainer.activeLinks[n]; exists { link.Disable() + } else { + utils.Debugf("Could not find active link for %s", name) } }