Docker0 default IP for 172.17.0.1
Use the command set docker0 IP:
Sudo ifconfig docker0 192.168.3.1 netmask 255.255.255.0
After setting, use the command check docker0, indeed modify success,
Then use the command to restart the docker service
Sudo service docker restart
To check the IP address of the docker0 became the default 172.17.0.1 again, when very sad...
Consult a great god, and how to solve this
CodePudding user response:
Your problem solved, please seek solution ~ ~ ~ thank you very much!!!!!!CodePudding user response:
In principle is not through the IP address of the container internal command to save the customThere are two ways to set a fixed IP:
1. Add the ifconfig command to/root/bashrc, but if it's not docker exe login, such as setting has no effect; If the container has a ring or cap - add=net_admin license, this is not recommended
2. From the external via IP netns exec ${NSID} ifconfig eth0 XXXX, this must write the script, each time you start the container should be through script
For example:
#!/bin/bash
[[" $1 "]] & amp; & Your_container_name="$1" | | {echo "the first parameter is the vessel name"; The exit 1; }
[[" $2 "]] & amp; & Your_image="$2" | | {echo "the name of the second parameter is the mirror image"; The exit 2; }
[[" $3 "]] & amp; & Your_exec="$3" | | {echo "the third parameter is a running program"; The exit 3; }
"]] [[" $4 & amp; & Your_ip="$4" | | {echo "the fourth parameter is fixed IP". The exit 4; }
Docker run - d - name=${your_container_name} ${your_image} ${your_exec}
The mkdir -p/var/run/netns
Unlink the/var/run/netns/${your_container_name}
Ln -s/proc/$(docker inspect - f {{. State. The Pid}} ${your_container_name})/ns/net/var/run/netns/${your_container_name}
IP netns exec ${your_container_name} ifconfig eth0 ${your_ip}
CodePudding user response:
Can modify the docker. Start the parameters of the service, the bind an IP or manually create a bridge, and then by specifying the parameter is bound to the new bridge is ok, don't have to set up each time