[Solved]-Unable to access local network IP from docker container-docker

score:1

I wanted to throw this answer out as it happened to me on Windows, but could really on any environment. I was using a bridge network on my local machine for a service I was developing and ran into similar issues, what was weird was that pinging our production physical servers (which started with a 10.10… IP pattern) or the random sites on the internet I was able to receive a response. But the physical dev server which sat on a 172.16… pattern didn’t work.

Finally I discovered through doing docker network inspect on the networks I had locally that one had created with the same subnet of 172.16… which overlapped my physical server IP address range. So when I was pinging the physical dev server, it was trying to find it on the virtual docker network, where it didn’t exist.

After deleting that network (it was a dev one I didn’t use), everything worked.

docker network rm {networkName}

If I had to keep the network, it is possible to change the subnet in the docker-compose file. If you need to change the conflicting subnet, the link to that is here How do configure docker compose to use a given subnet if a variable is set, or choose for itself if it isn’t?
That would look something like this (if you wanted a 12.12 subnet):

networks: 
  default:
    ipam:
      config:
        - subnet: 12.12.0.0/16