Error message in docker about user specified subnet

Viewed 8030

I'm trying to attribute an IP for a container using the --ip flag. But I get the following message:

Error response from daemon: user specified IP address is supported only when connecting to networks with user configured subnets.

What does this message mean? How do I get the container to run?

The network was created with the command: docker network create my_network_name

And the container is called with: docker run -it --net my_network_name --ip 172.22.0.30 image_name

1 Answers

When you create your network provide a subnet from the private IP range that is free in your network. Then when you create your container in this network pick an address from that subnet.

For instance with IP range 10.11.0.0/16 and container IP 10.11.0.10:

$ docker network create my_network_name --subnet=10.11.0.0/16
$ docker run -it --net my_network_name --ip 10.11.0.10 image_name

And here is an actual run:

$ docker --version
Docker version 19.03.6, build 369ce74a3c
$ uname -a
Linux 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ docker network create my_network_name --subnet=10.11.0.0/16
35a9e4e5fb4ff243202fc4f6b687901c3cbfcd8fe34e06290db5d257310417a2
$ docker run --rm -it --net my_network_name --ip 10.11.0.10 ubuntu
root@f0d283bc5023:/#

On another window:

$ docker network inspect my_network_name
[
    {
        "Name": "my_network_name",
        "Id": "35a9e4e5fb4ff243202fc4f6b687901c3cbfcd8fe34e06290db5d257310417a2",
        "Created": "2020-09-19T11:51:59.985580503-07:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "10.11.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "f0d283bc5023fbe8a1c854fd2bb5bdd121be7245013cfac62d9933f95ace7bbf": {
                "Name": "sleepy_colden",
                "EndpointID": "088fbd64b82e05920fda91b28ebb5b4a14c9fca3ac9fde457c8819663f6049df",
                "MacAddress": "02:42:0a:0b:00:0a",
                "IPv4Address": "10.11.0.10/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Related