5

Followed the https://stackoverflow.com/a/46266757 ("What is the best practice of docker + ufw under Ubuntu" answer by @mkubaczyk) guide to configure Docker with UFW properly but still unable to access Internet in containers.

What could the problem be?

Te Ri
  • 255
  • 2
  • 8

1 Answers1

6

The problem might be with containers you setup using docker-compose. By default new network is created for services in docker-compose.yml file. This leads that you are not just having docker0 interface with 172.17.0.0/16 subnet setup but also usually other interfaces 172.x.0.0/16.

To overcome this you should add more rules for your networks:

$ iptables -t nat -A POSTROUTING ! -o br-XXX -s 172.YYY.0.0/16 -j MASQUERADE

where br-XXX is interface name, 172.YYY.0.0/16 - subnet.

Alternatively, use single docker0 network by having in your docker-compose.yml for each service described:

    network_mode: bridge
Te Ri
  • 255
  • 2
  • 8