Ryan
Ryan

Reputation: 2660

Docker won't publish selected ports

I've created a container running ElasticSearch on Docker (9200 and 9300 are published so they can be accessed via the host).

$ docker run --name books-es -p 9200:9200 -p 9300:9300 -d elasticsearch
65937a0f8967390d33abaad50b55975cb9292be6692d29791c2e6c37ac5d2832

I then test to see if it's running:

$ docker exec books-es curl 127.0.0.1:9200
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   315{   0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  "name" : "Masque",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.0.0",
    "build_hash" : "de54438d6af8f9340d50c5c786151783ce7d6be5",
    "build_timestamp" : "2015-10-22T08:09:48Z",
    "build_snapshot" : false,
    "lucene_version" : "5.2.1"
  },
  "tagline" : "You Know, for Search"
}
  100   315    0     0   5204      0 --:--:-- --:--:-- --:--:--  5625

I identify the ip of my docker.

$ docker-machine ip default
192.168.99.100

But when testing the server from here, no response.

$ curl 192.168.99.100:9200
curl: (7) Failed to connect to 192.168.99.100 port 9200: Connection refused

Any ideas?

Upvotes: 2

Views: 163

Answers (3)

mike
mike

Reputation: 5213

Make sure that ElasticSearch listens on ip 0.0.0.0 and not 127.0.0.1.
Since docker exec books-es curl 127.0.0.1:9200 works, this seems to be the issue.

Upvotes: 1

VonC
VonC

Reputation: 1324347

Make sure to set the right environment variable:

eval $(docker-machine ip default)

And if that is not working, try with:

  • port mapping at the VM level

    VBoxManage controlvm "default" --natpf1 "tcp-port9200,tcp,,9200,,9200"
    VBoxManage controlvm "default" --natpf1 "udp-port9200,udp,,9200,,9200"
    
  • curl 127.0.0.1:9200

Upvotes: 0

Toan Tran
Toan Tran

Reputation: 1

You can try to map explicit port 192.168.99.100:9200:9200

Upvotes: 0

Related Questions