How Do You Troubleshoot the Docker Error “User specified IP address is supported only when connecting to networks with user configured subnets.”?

Problem scenario
You are trying to create a Docker image and assign it an IP address with the --ip flag. But you get this error: "/usr/bin/docker-current: Error response from daemon: User specified IP address is supported only when connecting to networks with user configured subnets."  How do you get your Docker command to work and resolve this problem?

Solution
#1  From the Linux server, run this command:  ip addr show

#2  Look at the results for eth0.  Find its "inet" IP address and subnet mask (e.g., 172.31.38.151/20). This is the internal IP address of the Docker server and its subnet mask in shorthand notation.  To determine the IP address of this Docker network you will create, mentally increment the last octet's integer value by 1 and keep the subnet mask for the construction of a command below.  If the calculated number is above 255, find an addressable IP number not being used and within the subnet mask for the server's IP address.

#3  Run a command like the following, however you may want to substitute "isolated_nw1" with the name of your choice for this user-defined network.  You must substitute x.x.x.x in the draft of the command below with the IP address this network will have (possibly as simple as one greater than the last octet of the server's internal IP address).  You will likely substitute 20 with the subnet mask short hand notation that the server's internal IP address has.  

docker network create --driver bridge isolated_nw1 --subnet x.x.x.x/20

The result may look like this:

docker network create --driver bridge isolated_nw1 --subnet 172.31.38.152/20

Take a note of this IP address and mentally increment the last octet one more time.  You'll use that IP address later for a Docker container.  But now you should have a user-defined Docker network with a subnet mask.

Leave a comment

Your email address will not be published.