Reputation: 29477
Mac running Docker Version 17.12.0-ce-mac55 (23011) here.
I have a very bizarre situation with Docker that I absolutely cannot explain!
http://localhost:9200
)localhost:80
and localhost:1521
respectivelydocker logs <containerId>
) the service startup without any errors whatsoeverlocalhost:9200
The exact steps to reproduce are:
./gradlew clean build && docker build -t locationservice .
docker run -it -p 9200:9200 -d --net="host" --name locationservice locationservice
docker ps
to obtain the <containerId>
, then you can keep hitting docker logs <containerId>
until you see it has started up without errorslocalhost:9200
, I get "connection refused" errors (see below)curl error is:
curl -X GET http://localhost:9200/bupo
curl: (7) Failed to connect to localhost port 9200: Connection refused
Some things I have ruled out:
localhost
is absolutely resolveable from the host because we're running in host
network mode and I have no problem connecting to nginx (port 80) and Oracle (port 1521) containersAny ideas what the problem could be?!
Upvotes: 2
Views: 3143
Reputation: 74630
Docker for Mac runs in a VM. --net=host
refers to the Linux VM hosts network stack not OSX. There is no direct network path from OSX to the Docker VM other than mapped ports.
Mapped ports (docker run -p Y:N
) in Docker for Mac are a little special, in addition to the user space proxy that runs on the Docker host normally, Docker for Mac also launches a user space proxy on OSX to listen on the same port and forward connections into the VM. The OSX process isn't started when using --net=host
(and the Linux one isn't either of course).
→ docker run --name nc --rm --net=host -dp 9200:9200 busybox nc -lk -p 9201 -e echo hey
→ docker inspect nc --format '{{ json .NetworkSettings.Ports }}'
{}
→ sudo lsof -Pni | grep 9200
→
Then without --net=host
→ docker run --name nc --rm -dp 9200:9200 busybox nc -lk -p 9201 -e echo hey
→ docker inspect nc --format '{{ json .NetworkSettings.Ports }}'
{"9200/tcp":[{"HostIp":"0.0.0.0","HostPort":"9200"}]}
→ sudo lsof -Pni | grep 9200
vpnkit 42658 matt 28u IPv4 0x57f79853269b81bf 0t0 TCP *:9200 (LISTEN)
vpnkit 42658 matt 29u IPv6 0x57f798532765ca9f 0t0 TCP [::1]:9200 (LISTEN)
If your app requires --net=host
then I would use Vagrant/Virtualbox to spin up a VM with a "Host Only" adapter. This means there is a direct network path that you can access from OSX on the VM. Here's the Vagrantfile I use.
Upvotes: 2
Reputation: 4669
Docker for Mac does not support host network mode very well: https://github.com/docker/for-mac/issues/1031
So at this moment the solution is to use default bridge mode.
Upvotes: 1