Docker uses the default 172.17. 0.0/16 subnet for container networking. If your network devices are in this subnet block, you will experience an IP conflict when the docker service or a container is started. To avoid IP conflict, you can change the default docker subnet.
We need to change 2 parts:
- Default docker0 interface
- Your docker project
You can’t overlap the interface with your project, therefor we need 2 different subnets.
In my case 192.168.5.0/24 for the docker0 container and 192.168.4.0/24 for my docker project
Update your docker to the latest version
sudo apt-get update
sudo apt upgrade docker-ce
Remove & Stop existing containers
sudo docker stop $(docker ps -q)
sudo docker rm -f $(docker ps -aq)
sudo docker network prune -f
sudo systemctl stop docker.socket
sudo systemctl stop docker
Change or Create the daemon config file
sudo nano /etc/docker/daemon.json
Change your network in the compose file
When the project starts and you bridged the network you will see when you type ip route that Docker will still create an extra network.
Therefor we also have to specify the other network in the compose file, this can not overlap with the docker0 network
- subnet: "192.168.4.0/24"
Reboot the server