3

I'm on mac os, I have a service running on my machine on localhost:8000

now I want to launch a docker image and hit this service from here.

I did a docker bridge and I use it from inside, but it is not working. Here are my steps:

My host ip:

ifconfig

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 98:01:a7:b0:2b:41
    inet 192.168.0.70 netmask 0xffffff00 broadcast 192.168.0.255
    media: autoselect
    status: active

I hit my service from host:

curl localhost:8000  #this is working!

I create a bridge and I use it:

docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
docker run --rm -it -v "$(pwd):/src" --network=dockernet  qatests /bin/bash

from inside docker, I do a curl but it is not working:

curl 192.168.0.1:8000 #it's not working :-(

any ideas?

Jurgo Boemo
  • 1,690
  • 1
  • 15
  • 21
  • Is the service running on localhost or all interfaces? What is the output of ss -tnl or netstat -tnl ? – Ricardo Branco Feb 19 '17 at 19:48
  • I believe what you are looking for is this [From inside of a Docker container, how do I connect to the localhost of the machine](http://stackoverflow.com/a/24326540/2127492) – jrbeverly Feb 19 '17 at 20:13

2 Answers2

3

You dont need to create a new network. You can use the default one (bridge).

Just check which ip is associated to the docker0 interface in your host with ip or ifconfig (in my case is 172.17.42.1), and use that ip from inside the container:

$ curl 172.17.42.1:8000
Salem
  • 12,808
  • 4
  • 34
  • 54
1

In the end, I've discovered that if I ping my pc ip, I can see it even from the docker image. For convenience, I did a lounch script witch get my current IP and launch the docker image making my ip accessible under "mymac" address So what i did is lunching

MY_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')

docker run --rm -it -v "$(pwd):/src" --add-host=mymac:$MY_IP qatests 
/bin/bash

inside docker I can now lunch:

curl mymac:8000 #it works! now mymac is my pc outside docker
Jurgo Boemo
  • 1,690
  • 1
  • 15
  • 21