Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option --ip ERROR: user specified IP address is supported only when connecting to networks with user configured subnets. #45806

Open
wushu037 opened this issue Jun 25, 2023 · 2 comments

Comments

@wushu037
Copy link

Description

I followed the documentation, created the network and set the static ip, but got an error

Reproduce

~ # docker network rm my-net
my-net
---------------------------------------------------------------------------------------------------------------
~ # docker network create my-net
e989f80b4b256365faffb20544eab4fa962da5014f8a65a5c0b4068a3fba6092
---------------------------------------------------------------------------------------------------------------
~ # docker network inspect my-net
[
    {
        "Name": "my-net",
        "Id": "e989f80b4b256365faffb20544eab4fa962da5014f8a65a5c0b4068a3fba6092",
        "Created": "2023-06-25T22:57:06.923726343+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
---------------------------------------------------------------------------------------------------------------
~ # docker run -it --network my-net --name c1 centos
[root@3711876fbb00 /]# exit
exit
---------------------------------------------------------------------------------------------------------------
~ # docker run -it --network my-net --ip 172.20.0.10  --name c2 centos
docker: Error response from daemon: user specified IP address is supported only when connecting to networks with user configured subnets.
ERRO[0000] error waiting for container:      

Expected behavior

No response

docker version

~ # docker version
Client: Docker Engine - Community
 Version:           23.0.5
 API version:       1.42
 Go version:        go1.19.8
 Git commit:        bc4487a
 Built:             Wed Apr 26 16:18:56 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.5
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.8
  Git commit:       94d3ad6
  Built:            Wed Apr 26 16:16:35 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

~ # docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.4
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.17.3
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 13
  Running: 3
  Paused: 0
  Stopped: 10
 Images: 17
 Server Version: 23.0.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 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: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc version: v1.1.5-0-gf19387a
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.11.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.7GiB
 Name: VM-16-8-centos
 ID: 9e74ddd2-6bb0-4003-9633-55fb5409e15d
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  101.35.187.40:5000
  127.0.0.0/8
 Registry Mirrors:
  https://registry.docker-cn.com/
  http://hub-mirror.c.163.com/
  https://docker.mirrors.ustc.edu.cn/
 Live Restore Enabled: false

Additional Info

No response

@wushu037 wushu037 added kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage labels Jun 25, 2023
@thaJeztah
Copy link
Member

Looking at the code, this seems to be intentional (I'd have to look into history, but my guess here is that if no explicit subnet is configured for the network, the subnet could change between restarts (?)).

The documentation doesn't show that in the example though, so probably should be fixed

/cc @akerouanton @dvdksn

@bsousaa bsousaa removed the kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. label Jun 26, 2023
@wushu037
Copy link
Author

@thaJeztah , thank you for your handling.

In addition to this, there is a bug: networks created with -subnet do not automatically set the gateway, you need to specify it with -gateway.
However, this document mentions that if -gateway is omitted, the engine will automatically set the gateway.

If you omit the --gateway flag the Engine selects one for you from inside a preferred pool.

The reason for saying "not automatically set" is that you can't see the gateway when you look at the network information with the docker inspect command.
However, if you add the container to the network, you can see the gateway address again by running route -n inside the container, which is .1 of subnet by default, e.g. 172.10.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants