normalizeNetMode checks whether the network mode references a network by a partial ID. In that case, it replaces the partial ID with the full network ID. TODO(aker): transform ID into name when the referenced network is one of the predefined.
(ctr *container.Container)
| 936 | // partial ID with the full network ID. |
| 937 | // TODO(aker): transform ID into name when the referenced network is one of the predefined. |
| 938 | func (daemon *Daemon) normalizeNetMode(ctr *container.Container) error { |
| 939 | if ctr.HostConfig.NetworkMode.IsUserDefined() { |
| 940 | netMode := ctr.HostConfig.NetworkMode.NetworkName() |
| 941 | nw, err := daemon.FindNetwork(netMode) |
| 942 | if err != nil { |
| 943 | return fmt.Errorf("could not find a network matching network mode %s: %w", netMode, err) |
| 944 | } |
| 945 | |
| 946 | if netMode != nw.ID() && netMode != nw.Name() { |
| 947 | ctr.HostConfig.NetworkMode = containertypes.NetworkMode(nw.ID()) |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | return nil |
| 952 | } |
| 953 | |
| 954 | func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerPrefixOrName string) (*container.Container, error) { |
| 955 | nc, err := daemon.GetContainer(connectedContainerPrefixOrName) |
no test coverage detected