Change the Default Docker Subnet with SystemD

Docker uses the default 172.17.0.0/16 subnet for container networking.

This will become a problem if you use the same subnet for your local network.

To change the default subnet on the docker0 interface with systemd (CentOS 7), create the following directory:

$ sudo mkdir -p /etc/systemd/system/docker.service.d/

Create the configuration file /etc/systemd/system/docker.service.d/override.conf with the following content:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --bip 172.200.0.1/16

Where 172.200.0.1/16 is your new Docker subnet.

Reload systemd manager configuration:

$ sudo systemctl daemon-reload

Restart Docker service:

$ sudo systemctl restart docker.service

Verify:

$ ip addr show dev docker0
4: docker0:  mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:c8:21:8c:19 brd ff:ff:ff:ff:ff:ff
    inet 172.200.0.1/16 brd 172.200.255.255 scope global docker0
       valid_lft forever preferred_lft forever

Leave a Reply

Your email address will not be published. Required fields are marked *