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.20.0.1/16

Where 172.20.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: <NO-CARRIER,BROADCAST,MULTICAST,UP> 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.20.0.1/16 brd 172.20.255.255 scope global docker0
       valid_lft forever preferred_lft forever

2 thoughts on “Change the Default Docker Subnet with SystemD

  1. Thank you. It works.
    172.200.0.1/16 is bad example because this is not private IP address range. This is internet range
    Some colleagues may use this config “as is” and face issue

Leave a Reply

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