I'm using docker on my Ubuntu 20.10 machine. I'd like to use docker-compose to set up a few containers on a user defined bridge network.
My current setup for my docker_compose.yml
is as follows:
version: "3.5"
services:
webserver:
image: httpd
networks:
default:
ipv4_address: 172.16.0.2
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.0.0/16
gateway: 172.16.0.1
driver_opts:
com.docker.network.bridge.enable_icc: "true"
com.docker.network.bridge.enable_ip_masquerade: "true"
com.docker.network.bridge.host_binding_ipv4: "0.0.0.0"
com.docker.network.bridge.name: "docker1"
Running docker-compose up
works fine and creates the network with the container, and if I try to interact with the container from the host:
wget 172.16.0.2
It works as I would expect it to. However, when I try to add another container to the network and attempt to connect to it, i.e:
docker run --rm -it --net=test1_default alpine wget 172.16.0.2
The added container is unable to connect. It's also worth noting that no container on the network is able to access the internet either.
I remembered being able to interact between containers fine that were added to the default bridge network, so I created a modified docker-compose.yml
just to test it out:
version: "3.5"
services:
webserver:
image: httpd
network_mode: bridge
It was given the IP 172.17.0.2
. Trying the same command as before on the this network:
docker run --rm -it --net=bridge alpine wget 172.17.0.2
works perfectly fine! I also tried to ping 8.8.8.8
and the containers appear to connect to the internet fine as well.
I don't believe this is a problem with docker-compose creating the bridge network because I encounter the same issue if I create the docker network manually and try adding containers to it.
Any help would be greatly appreciated. I'm happy to provide more information on the host system configuration as well.
Seems trivial, but I was able to resolve the issue by uninstalling docker and reinstalling. My guess is that something got screwed up in my recent upgrade from Ubuntu 18.04 to 20.10