1

I have created a custom network by using command:

docker network create --driver=bridge --subnet=192.168.1.0/16 --gateway=192.168.1.1 -o "com.docker.network.bridge.host_binding_ipv4"="0.0.0.0" -o "com.docker.network.bridge.enable_icc"="true" -o "com.docker.network.bridge.enable_ip_masquerade"="true" my-net

Post creation I have created docker containers using docker compose:

version: "3"
services:
web:
build: './UI'
ports:
 - "80:80"
tty: true
links:
 - service
networks:
 my-net:
  ipv4_address: 192.168.1.2

service:
build: './Service'
ports:
 - "8090:8090"
tty: true
networks:
 my-net:
  ipv4_address: 192.168.1.3

networks:
my-net:
external:
  name: my-net

Now when I am pinging the containers internally, I am getting the response. But when I am trying pinging google.com, container is unable to ping it.

I also ran this command, but no success.

sysctl net.ipv4.conf.all.forwarding=1
  • 2
    Possible duplicate of [My docker container has no internet](https://stackoverflow.com/questions/20430371/my-docker-container-has-no-internet) – juanlumn Jul 27 '18 at 11:32

1 Answers1

0

I had this problem a while ago, and a simple workaround is adding external DNS entries (Google's, in this case) to your service in docker-compose.yml:

services:
  web:
    ...
    dns:
      - 8.8.8.8
      - 4.4.4.4

This quickly solved my problem, at least for development/test environment.

I know probably there are more complex (and probably more secure) ways of doing it, but this really solved my problem. I believe creating a bridge network could solve this, but I haven't tested it.

There could also be a problem with firewoll configurations (even though maybe in this case pign would not work also). More about it can be found in this entry from Docker Forum (docker in windows): Docker DNS not responding from inside a container.

I hope this helps! :-)

Kaosnoff
  • 1
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 01:16