How to change ip address of docker0 bridge interface on Docker Toolbox How to change ip address of docker0 bridge interface on Docker Toolbox docker docker

How to change ip address of docker0 bridge interface on Docker Toolbox


To change the IP address Docker will set on it's docker0 interface, you have to use the --bip option which defines the CIDR (eg. --bip=10.32.57.1/24), see "Customize the docker0 bridge" in Docker user guide.

Docker Toolbox uses Boot2Docker (running in a virtual machine) which is based on the Tiny Core Linux OS.

Docker daemon reads /var/lib/boot2docker/profile before starting (see "Local Customisation" in Boot2Docker's FAQ) where a EXTRA_ARGS variable is ready to be filled with your custom settings.

Just add your --bip=... in EXTRA_ARGS's value part and restart the daemon.

The following command (to type in the Docker Quickstart Terminal) will stop the Docker daemon, drop any existing rule, delete the interface, add a --bip option to /var/lib/boot2docker/profile and restart the daemon:

docker-machine ssh default "\    sudo /etc/init.d/docker stop ; \    sudo iptables -t nat -F POSTROUTING ; \    sudo ip link del docker0 ; \    sudo sed -i \"/^EXTRA_ARGS='\\$/a --bip=10.32.57.1/24\" /var/lib/boot2docker/profile ; \    sudo /etc/init.d/docker start \    "

(Content of /var/lib/boot2docker is persisted between Boot2Docker VM restarts so running this command once should suffice)

You can check with:

docker-machine ssh default "ip a show dev docker0"

If anyone needs the same manipulation on Debian (without Boot2Docker thus):

For Sysvinit:

cat >> /etc/default/docker <<EOT# Change Docker network bridge:DOCKER_OPTS="--bip=10.32.57.1/24" # "3257" = "dckr" on a phone keyboardEOT

For systemd:

cat > /etc/systemd/system/docker.service <<'EOT'[Service]EnvironmentFile=-/etc/sysconfig/dockerEnvironmentFile=-/etc/sysconfig/docker-storageEnvironmentFile=-/etc/sysconfig/docker-networkExecStart=ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS \          $DOCKER_STORAGE_OPTIONS \          $DOCKER_NETWORK_OPTIONS \          $BLOCK_REGISTRY \          $INSECURE_REGISTRYEOTmkdir /etc/sysconfigcat > /etc/sysconfig/docker <<EOTOPTIONS="--bip=10.32.57.1/24"EOTsystemctl daemon-reload

Then (for both Sysvinit and systemd):

service docker stopiptables -t nat -F POSTROUTINGip link del docker0service docker startiptables -t nat -L -n # Check if POSTROUTING table is OK