0

How to bridge docker container and localhost service?

My service inside docker container cant talk with mongidb server, running on host machine

  • You should ask this question on ServerFault. StackOverflow is for programming questions. – ofrommel Jul 04 '18 at 13:27
  • 1
    Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze Jul 04 '18 at 15:38

2 Answers2

0

I too faced this situation. You can use your localhost services in docker.

Steps:
 1. In your MongoDb (or any service) conf file, bind that service with machine's ip ( not localhost or 127.0.0.1, it might look like 192.168.x.x) and restart it.
 2. In your docker, access service via given machine's ip.

Hope it helps.

BugHunter
  • 1,194
  • 2
  • 9
  • 15
0

As @David Maze pointed out, this is answered here for Mac and Windows machines, and this Github issue contains a pending Linux feature that will make the solution work for Linux too. That answer says use host.docker.internal instead of localhost to access your host machine's IP from within your containers.

Brendan Goggin
  • 2,061
  • 14
  • 14