mirror of
https://github.com/docker/cli.git
synced 2026-01-26 15:41:42 +03:00
Fix link doesn't work sometimes when container start with multiple networks
If there is multiple networks to connect to on container starting, the order of these networks is random because we "range a map". But the defautl network "bridge" should be connected first since only "bridge" support link and we should have do some settings on sandbox creation, and only the first connect will setting the sandbox. Signed-off-by: Lei Jitang <leijitang@huawei.com> Upstream-commit: 57c0a653e3d0055e63db399019b3b16d4ac97004 Component: engine
This commit is contained in:
@@ -397,7 +397,21 @@ func (daemon *Daemon) allocateNetwork(container *container.Container) error {
|
||||
updateSettings = true
|
||||
}
|
||||
|
||||
// always connect default network first since only default
|
||||
// network mode support link and we need do some setting
|
||||
// on sanbox initialize for link, but the sandbox only be initialized
|
||||
// on first network connecting.
|
||||
defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName()
|
||||
if nConf, ok := container.NetworkSettings.Networks[defaultNetName]; ok {
|
||||
if err := daemon.connectToNetwork(container, defaultNetName, nConf, updateSettings); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
for n, nConf := range container.NetworkSettings.Networks {
|
||||
if n == defaultNetName {
|
||||
continue
|
||||
}
|
||||
if err := daemon.connectToNetwork(container, n, nConf, updateSettings); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user