0
votes

In short - Can I run Elasticsearch & Dropwizard app in separate docker containers and allow them to see each other?

I am running Elasticsearch 6.2.2 from Docker (on mac). using the command..

docker run -p 9200:9200 -p 9300:9300 -e "network.host=0.0.0.0" \ 
-e "http.port=9200"  -e "discovery.type=single-node" \
docker.elastic.co/elasticsearch/elasticsearch:6.2.2

I can access Elasticsearch (POST & GET) fine using Postman directly on mac e.g

localhost:9200/testindex/_search

However when running a Dropwizard application from a different docker image which accesses the docker Elasticsearch instance, I get connection refused using same host and port (localhost 9200).

I have no problems at all when running the Dropwizard app direct from an IDE, only when its running from a docker image and accessing ES from a different image.

docker image -p 8080:8080 -p 8081:8081 testapp

Has anyone else had similar issues or solved this in the past? I'm assuming it 'network' related and that connecting to localhost from one docker image will not be map to the other docker image

1
If you're running multiple Docker containers locally, you could probably avoid the complexities of network configuration by using Docker-Compose - it generally just works.Oliver Charlesworth

1 Answers

1
votes

The issue you are facing is in the url you pass to the dropwizard container. As a container by default has its own networking, a value of localhost means the dropwizard container itself, not what you see as your local host from outside the container.

Please have a look at docker networking, how you can link two containers by name. I would suggest to check out docker-compose for multi-container setups on a local machine.

What would also work (but is not good practice) is to pass the dropwizard container the ip of your machine as elasticsearch host because you created a port mapping from your host into the elasticsearch container. But better have a look at compose to do it as it is supposed to be done.

For details how to use compose please have a look at this answer with a similar example.