From 746ba127bfb3556d378ccd8b2c725b490d090334 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 30 Oct 2013 08:15:12 -0700 Subject: [PATCH] Hotfix: Migrate public mappings after upgrade --- container.go | 5 ++++- utils.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/container.go b/container.go index 43792d5f00..1888e91ff9 100644 --- a/container.go +++ b/container.go @@ -1054,10 +1054,13 @@ func (container *Container) allocateNetwork(hostConfig *HostConfig) error { if container.Config.PortSpecs != nil { utils.Debugf("Migrating port mappings for container: %s", strings.Join(container.Config.PortSpecs, ", ")) - if err := migratePortMappings(container.Config); err != nil { + if err := migratePortMappings(container.Config, hostConfig); err != nil { return err } container.Config.PortSpecs = nil + if err := container.SaveHostConfig(hostConfig); err != nil { + return err + } } portSpecs := make(map[Port]struct{}) diff --git a/utils.go b/utils.go index cffee05615..8043b16d47 100644 --- a/utils.go +++ b/utils.go @@ -265,15 +265,19 @@ func parsePort(rawPort string) (int, error) { return int(port), nil } -func migratePortMappings(config *Config) error { +func migratePortMappings(config *Config, hostConfig *HostConfig) error { if config.PortSpecs != nil { - // We don't have to worry about migrating the bindings to the host - // This is our breaking change - ports, _, err := parsePortSpecs(config.PortSpecs) + ports, bindings, err := parsePortSpecs(config.PortSpecs) if err != nil { return err } config.PortSpecs = nil + if len(bindings) > 0 { + if hostConfig == nil { + hostConfig = &HostConfig{} + } + hostConfig.PortBindings = bindings + } if config.ExposedPorts == nil { config.ExposedPorts = make(map[Port]struct{}, len(ports))