Change Dockers IP

Sometimes the default Docker IP has to be changed.

 

Docker bridge

To change the IP of the docker bridge docker0 follow the following instructions extracted from this link
1- Remove the current docker bridge:

ip link del docker0

 

2 – Edit (or create) the file /etc/docker/daemon.json and add an “bip” entry with the desired IP address and netmask for the docker0 bridbe:

{
"bip": "174.17.0.1/24"
}

 

3 -Restart the service:

service docker stop
service docker start

Docker swarm

To change the IP of the docker bridge (docker_gwbridge) from a swarm follow the following instructions extracted from this link

 

Leave the swarm:

docker swarm leave

Remove the interface:

docker network rm docker_gwbridge

 

Create the node:

docker network create --subnet 174.20.0.0/20 --gateway 174.20.0.1 -o com.docker.network.bridge.name=docker_gwbridge -o com.docker.network.bridge.enable_icc=false docker_gwbridge

 

Check the new IPs

Execute ifconfig:

[root@mihost docker]# ifconfig
docker0: flags=4099 mtu 1500
inet 174.17.0.1 netmask 255.255.255.0 broadcast 174.17.0.255
ether 02:42:aa:6c:10:e1 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker_gwbridge: flags=4099 mtu 1500
inet 174.20.0.1 netmask 255.255.240.0 broadcast 174.20.15.255
ether 02:42:ab:47:ca:57 txqueuelen 0 (Ethernet)
RX packets 114522173 bytes 70561381028 (65.7 GiB)
RX errors 0 dropped 75062 overruns 0 frame 0
TX packets 52702908 bytes 22974463339 (21.3 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s