mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Hotfix: Migrate public mappings after upgrade
This commit is contained in:
parent
caa7cf14c0
commit
746ba127bf
2 changed files with 12 additions and 5 deletions
|
@ -1054,10 +1054,13 @@ func (container *Container) allocateNetwork(hostConfig *HostConfig) error {
|
||||||
|
|
||||||
if container.Config.PortSpecs != nil {
|
if container.Config.PortSpecs != nil {
|
||||||
utils.Debugf("Migrating port mappings for container: %s", strings.Join(container.Config.PortSpecs, ", "))
|
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
|
return err
|
||||||
}
|
}
|
||||||
container.Config.PortSpecs = nil
|
container.Config.PortSpecs = nil
|
||||||
|
if err := container.SaveHostConfig(hostConfig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
portSpecs := make(map[Port]struct{})
|
portSpecs := make(map[Port]struct{})
|
||||||
|
|
12
utils.go
12
utils.go
|
@ -265,15 +265,19 @@ func parsePort(rawPort string) (int, error) {
|
||||||
return int(port), nil
|
return int(port), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func migratePortMappings(config *Config) error {
|
func migratePortMappings(config *Config, hostConfig *HostConfig) error {
|
||||||
if config.PortSpecs != nil {
|
if config.PortSpecs != nil {
|
||||||
// We don't have to worry about migrating the bindings to the host
|
ports, bindings, err := parsePortSpecs(config.PortSpecs)
|
||||||
// This is our breaking change
|
|
||||||
ports, _, err := parsePortSpecs(config.PortSpecs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config.PortSpecs = nil
|
config.PortSpecs = nil
|
||||||
|
if len(bindings) > 0 {
|
||||||
|
if hostConfig == nil {
|
||||||
|
hostConfig = &HostConfig{}
|
||||||
|
}
|
||||||
|
hostConfig.PortBindings = bindings
|
||||||
|
}
|
||||||
|
|
||||||
if config.ExposedPorts == nil {
|
if config.ExposedPorts == nil {
|
||||||
config.ExposedPorts = make(map[Port]struct{}, len(ports))
|
config.ExposedPorts = make(map[Port]struct{}, len(ports))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue