curl - Cannot access ports on MacOSX host from within docker container -


these steps took:

prework:

first:

docker-machine create -d virtualbox default 

then, created container following dockerfile:

from centos:latest

nothing else — copy of centos. built container:

docker build -t mycontainer . 

and run it:

docker run -it --net="host" --name="test" -p 9200:9200 mycontainer 

problem: when go inside container , try access service running on macosx (such simple webserver or local elasticsearch), get:

curl localhost:9200 curl: (7) failed connect localhost:9200; connection refused 

i same error within docker vm (docker-machine ssh default).

i tried port forwarding in virtualbox, setting 9200 9200 — did not help.

any ideas?

you cannot connect docker container port on host localhost:port (unless run container --net="host" )

you need specify ip address of host connect.

please check ip on host:

dude-server:stackoverflow cwoehrle$ ping $(hostname) ping dude-server (192.168.1.169): 56 data bytes 64 bytes 192.168.1.169: icmp_seq=0 ttl=64 time=0.053 ms 64 bytes 192.168.1.169: icmp_seq=1 ttl=64 time=0.069 ms 

in container (use ip respectively):

root@8975fada1ac3:/# nc 192.168.1.169 9200 

edited: connect host ports on mac can use default gateway address 10.0.2.2, e.g. nc 10.0.2.2 9200


Comments