0

I am creating an elasticsearch image and want to run the container on some remote machine.

Suppose the machine hostname is "abc.com", so I am accessing the URL as "abc.com:9200" to access elasticsearch. After testing successfully, this container will be deployed to Kubernetes. But to access elasticsearch (for filebeat, kibana and logstash) I need some static hostname so that while accessing it from different applications will be easy. I am trying to make the hostname "elasticsearch" and want it to access as "http://elasticsearch:9200".

PS: I am new to Docker, and want to clear my doubts by asking silly questions

I have tried adding "--hostname" and "--add-host", both didnt worked. docker run -d --name=elasticsearch \ --network=elk \ -p=9200:9200 -p 9300:9300 \ --hostname "elasticsearch" \ elasticsearch:7.17.6

Expecting to get the response by accessing "http://elsaticsearch:9200"

Albina
  • 1,901
  • 3
  • 7
  • 19
  • Docker itself can't manage the DNS in the surrounding environment. `docker run --hostname` only sets what the container believes its own hostname is, which is very occasionally useful (I don't remember if Elasticsearch publishes this name in the `/_index/nodes` listing for example) but doesn't affect other containers or other hosts at all. – David Maze Dec 20 '22 at 14:32
  • (You need to set up your other components so that the host names are configurable; it doesn't really work in practice to hard-code host names and require every environment to have identical networking and deployment setup.) – David Maze Dec 20 '22 at 14:33

0 Answers0