Skip to content

Networking - container always uses Name of network #40901

@eyJhb

Description

@eyJhb

Description
It is possible to create multiple networks with the same name, if you use the API (documented here - #18864), which is all fine and dandy.
The problem is, that if you specify a network for a container using the ID, it will add that network to the container but it will the change it to reference the network by using the name.

Now we have a container where the network name is ambiguous, as multiple networks have the same name, as it is not using the id specified but resolves it to the less unique name.

Steps to reproduce the issue:

  1. Create two of the same networks using (run the command twice)
    • curl --unix-socket /var/run/docker.sock -X POST -H "Content-Type: application/json" -d '{"name": "testing123"}' http/networks/create
  2. Create a container using one of the networks (by id)
    • docker create --network <networkid> --name testingcontainer alpine
  3. Start it docker start testingcontainer

Describe the results you received:

error response from daemon: network testing123 is ambiguous (2 matches found on name)
Error: failed to start containers: testingcontainer
       "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "testing123": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }

Describe the results you expected:
That it starts and use the network by ID.
I think there are four solutions.

  1. Do nothing about it
  2. Always use the network ID, and never name (harder to spot the networks, but there can be made nice things around this on the client)
  3. Use the piece of information specified, so if I add it by name, then it will use name, if I add by id use the ID (if a network with the same name is created after, then we have trouble again as opposed to 2)
  4. Same as 2, but add a name field so one can easily see the name of the network

How will any of these affect e.g. swarm etc. is one of the most important questions in the issue.

Also I think some of the code at fault is here

container.NetworkSettings.Networks[n.Name()] = &network.EndpointSettings{
EndpointSettings: endpointConfig,
}

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.14.1
 Git commit:        afacb8b7f0d8d4f9d2a8e8736e9c993e672b41f3
 Built:             Mon Apr 27 08:55:01 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.14.1
  Git commit:       afacb8b7f0d8d4f9d2a8e8736e9c993e672b41f3
  Built:            Thu Jan  1 00:00:01 1970
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          
  GitCommit:        .m
 runc:
  Version:          1.0.0-rc10
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit:        

Output of docker info:

Client:
 Debug Mode: false

Server:
 Containers: 41
  Running: 0
  Paused: 0
  Stopped: 41
 Images: 9
 Server Version: 19.03.8
 Storage Driver: overlay2
  Backing Filesystem: <unknown>
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc runsc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: .m
 runc version: 
 init version: 
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.4.33
 Operating System: NixOS 20.03 (Markhor)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.47GiB
 Name: eos
 ID: OTSJ:5IVM:764D:7UST:PNIW:MHXG:GFII:EJ6X:LUBX:AT6E:C4E4:EFLG
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions