How to fix a Docker subnet conflict with the local network when using docker-compose?
sobes.tech AI
Answer from AI
If the default Docker subnet conflicts with the local network when using docker-compose, you can change the subnet assigned to Docker networks to avoid overlaps.
To do this, you can explicitly specify a custom network with the desired subnet range in your docker-compose.yml:
networks:
custom_network:
driver: bridge
ipam:
config:
- subnet: 192.168.100.0/24
Then, specify this network in your services:
services:
app:
image: myapp
networks:
- custom_network
It's important to choose a subnet that does not overlap with your local network. You can also check current Docker networks with the command docker network ls and remove unnecessary ones using docker network rm.
If conflicts occur frequently, you can configure the Docker daemon by changing the default settings in the /etc/docker/daemon.json file, specifying a different subnet range for the bridge network.