Browse code

Hotfix: Migrate public mappings after upgrade

Michael Crosby authored on 2013/10/31 00:15:12
Showing 2 changed files
... ...
@@ -1054,10 +1054,13 @@ func (container *Container) allocateNetwork(hostConfig *HostConfig) error {
1054 1054
 
1055 1055
 	if container.Config.PortSpecs != nil {
1056 1056
 		utils.Debugf("Migrating port mappings for container: %s", strings.Join(container.Config.PortSpecs, ", "))
1057
-		if err := migratePortMappings(container.Config); err != nil {
1057
+		if err := migratePortMappings(container.Config, hostConfig); err != nil {
1058 1058
 			return err
1059 1059
 		}
1060 1060
 		container.Config.PortSpecs = nil
1061
+		if err := container.SaveHostConfig(hostConfig); err != nil {
1062
+			return err
1063
+		}
1061 1064
 	}
1062 1065
 
1063 1066
 	portSpecs := make(map[Port]struct{})
... ...
@@ -265,15 +265,19 @@ func parsePort(rawPort string) (int, error) {
265 265
 	return int(port), nil
266 266
 }
267 267
 
268
-func migratePortMappings(config *Config) error {
268
+func migratePortMappings(config *Config, hostConfig *HostConfig) error {
269 269
 	if config.PortSpecs != nil {
270
-		// We don't have to worry about migrating the bindings to the host
271
-		// This is our breaking change
272
-		ports, _, err := parsePortSpecs(config.PortSpecs)
270
+		ports, bindings, err := parsePortSpecs(config.PortSpecs)
273 271
 		if err != nil {
274 272
 			return err
275 273
 		}
276 274
 		config.PortSpecs = nil
275
+		if len(bindings) > 0 {
276
+			if hostConfig == nil {
277
+				hostConfig = &HostConfig{}
278
+			}
279
+			hostConfig.PortBindings = bindings
280
+		}
277 281
 
278 282
 		if config.ExposedPorts == nil {
279 283
 			config.ExposedPorts = make(map[Port]struct{}, len(ports))