Hotfix: Migrate public mappings after upgrade

Upstream-commit: 79bf2c2b0e898fdc93db66ddc1622bb79c0b83f8
Component: engine
This commit is contained in:
Michael Crosby
2013-10-30 09:02:23 -07:00
parent e20477be1c
commit cae555c9ca
2 changed files with 12 additions and 5 deletions
+4 -1
View File
@@ -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{})
+8 -4
View File
@@ -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))