daemon: Daemon.setupLinkedContainers: don't fetch linked containers if not used

This function was unconditionally trying to fetch linked container, even
if the container was not using the default bridge (the only network that
supports legacy links).

Also removing the intermediate variable, as daemon.children, through
daemon.linkindex.children already returns a variable with a copy of these
links.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-01-19 15:31:50 +01:00
parent 6160aeb6e2
commit 53fec9813f

View File

@@ -30,15 +30,13 @@ import (
)
func (daemon *Daemon) setupLinkedContainers(ctr *container.Container) ([]string, error) {
var env []string
children := daemon.children(ctr)
bridgeSettings := ctr.NetworkSettings.Networks[network.DefaultNetwork]
if bridgeSettings == nil || bridgeSettings.EndpointSettings == nil {
return nil, nil
}
for linkAlias, child := range children {
var env []string
for linkAlias, child := range daemon.children(ctr) {
if !child.IsRunning() {
return nil, fmt.Errorf("Cannot link to a non running container: %s AS %s", child.Name, linkAlias)
}