From 103a4e0676f0099759e6f9a29ea1c9dc32766806 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Mon, 29 Sep 2014 15:51:36 -0700 Subject: [PATCH] Network Allocation: Proper rollback in case of failure allocation. Signed-off-by: Andrea Luzzardi --- daemon/container.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon/container.go b/daemon/container.go index 0d97d726a..6bbdb7570 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -463,10 +463,12 @@ func (container *Container) allocateNetwork() error { if container.Config.PortSpecs != nil { if err := migratePortMappings(container.Config, container.hostConfig); err != nil { + eng.Job("release_interface", container.ID).Run() return err } container.Config.PortSpecs = nil if err := container.WriteHostConfig(); err != nil { + eng.Job("release_interface", container.ID).Run() return err } } @@ -496,6 +498,7 @@ func (container *Container) allocateNetwork() error { for port := range portSpecs { if err := container.allocatePort(eng, port, bindings); err != nil { + eng.Job("release_interface", container.ID).Run() return err } } @@ -1149,7 +1152,6 @@ func (container *Container) allocatePort(eng *engine.Engine, port nat.Port, bind return err } if err := job.Run(); err != nil { - eng.Job("release_interface", container.ID).Run() return err } b.HostIp = portEnv.Get("HostIP")