Change docker default subnet

Docker

Environment: Arch Linux

Kernel: 4.5.4-1-ARCH

Docker: Docker version 1.11.2, build b9f10c9

Docker default subnet

The default subnet about docker bridge docker0 is 172.16.0.0/16

➜  ~ ip a
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:8b:28:d9:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.233.0/16 scope global docker0
       valid_lft forever preferred_lft forever

Change default subnet

Open the /etc/systemd/system/multi-user.target.wants/docker.service file, at the [Service] block add the --bip argument at the end of ExecStart.

The subnet you can choose any as long as you stick within the ranges defined in RFC 1918.

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/docker daemon -H fd:// --bip=192.168.233.0/16

Restart service

Warning: docker.service changed on disk. Run systemctl daemon-reload to reload units.

Restart the service via systemctl restart docker

➜  ~ ip a
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:8b:28:d9:62 brd ff:ff:ff:ff:ff:ff
    inet 192.168.233.0/16 scope global docker0
       valid_lft forever preferred_lft forever

Referance

https://github.com/docker/docker/blob/3d13fddd2bc4d679f0eaa68b0be877e5a816ad53/docs/userguide/networking/default_network/custom-docker0.md

http://container-solutions.com/set-the-ip-of-the-docker-bridge-with-systemd/

Loading Disqus comments...
Table of Contents