Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change docker containers IP address

My network is on 10.0.0.0 when I start docker containers they have a different set of IP addresses (172.17.42.1)

How do I get my containers to start up on the same 10.0.0.0 network

I have configured br0 and for it to be static and I would like docker0 to share the same ip range so that it allocates ip address to containers on the same network

like image 533
user3001829 Avatar asked Dec 25 '13 09:12

user3001829


3 Answers

I hope this link will help you http://jpetazzo.github.io/2013/10/16/configure-docker-bridge-network/

In short, just add to /etc/network/interfaces the following:

auto docker0
iface docker0 inet static
    address 172.30.0.1
    netmask 255.255.255.0
    bridge_ports dummy0
    bridge_stp off
    bridge_fd 0

And restart the interface, or restart PC.

ifdown docker0
ifup docker0
like image 199
beyrem Avatar answered Sep 22 '22 03:09

beyrem


Already accept answer isn't really an answer but just a link. So I will provide solution which works for me. Important to note that solution may get overwritten by docker upgrade. You should be asked about replacing your docker configuration on upgrading package. Config path is valid as of Ubuntu 15.10.

sudo vim /etc/default/docker

add this line to file

DOCKER_OPTS="--bip=10.66.33.10/24"

then reboot
after reboot start a container

docker run -it --name t2 jangorecki/r-base-dev /bin/bash

and check ip of a container

docker inspect --format '{{ .NetworkSettings.IPAddress }}' t2
like image 21
jangorecki Avatar answered Sep 20 '22 03:09

jangorecki


On my Centos container I do this:

docker exec -it c1 bash -c "echo -e 'IPADDR=172.17.0.4 \n HOSTNAME=c1' >> /etc/sysconfig/network-scripts/ifcfg-eth0; /etc/init.d/network restart";
like image 36
DMin Avatar answered Sep 21 '22 03:09

DMin