Skip to content

Instantly share code, notes, and snippets.

@ewenchou
Last active September 15, 2016 18:26
Show Gist options
  • Save ewenchou/bd5e9ae590210c51b3eab42559f3bc2e to your computer and use it in GitHub Desktop.
Save ewenchou/bd5e9ae590210c51b3eab42559f3bc2e to your computer and use it in GitHub Desktop.
Customize docker bridge subnet

Change the Docker Daemon's Startup Options (systemd)

  1. Stop docker daemon: sudo systemctl stop docker

  2. Override the docker daemon startup options via systemd by adding a conf file

     sudo mkdir -p /etc/systemd/system/docker.service.d
     sudo vim /etc/systemd/system/docker.service.d/docker.conf
    
  3. Override the ExecStart command and add the --bip option

     [Service]
     ExecStart=
     ExecStart=/usr/bin/dockerd -H fd:// --bip=198.18.0.1/24
    
  4. Install bridge-utils: sudo apt-get install -y bridge-utils

  5. Bring down and delete the docker0 bridge.

     sudo ip link set down docker0
     sudo brctl delbr docker0
    
  6. Reload systemd daemon: sudo systemctl daemon-reload

  7. Start docker: sudo systemctl start docker

Note:

If you created bridged other than docker0 you need to use docker command, docker network rm ... to remove them (i.e. the brctl delbr ... command is not enough because the docker daemon will recreate them).

# Control the bridge subnets created by docker-compose
version: '2'
services:
web:
image: ubuntu
tty: true
networks:
mynet:
ipv4_address: 198.18.1.2
networks:
mynet:
driver: bridge
ipam:
driver: default
config:
- subnet: 198.18.1.0/24
gateway: 198.18.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment