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:
- 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
- Create a container using one of the networks (by id)
docker create --network <networkid> --name testingcontainer alpine
- 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.
- Do nothing about it
- 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)
- 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)
- 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.):
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:
curl --unix-socket /var/run/docker.sock -X POST -H "Content-Type: application/json" -d '{"name": "testing123"}' http/networks/createdocker create --network <networkid> --name testingcontainer alpinedocker start testingcontainerDescribe the results you received:
Describe the results you expected:
That it starts and use the network by ID.
I think there are four solutions.
namefield so one can easily see the name of the networkHow 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
moby/daemon/container_operations.go
Lines 294 to 296 in 0a5cec2
Additional information you deem important (e.g. issue happens only occasionally):
Output of
docker version:Output of
docker info:Additional environment details (AWS, VirtualBox, physical, etc.):