Home > Software design >  Docker's container name can not be resolved
Docker's container name can not be resolved

Time:10-09

I just tried to create two containers for Elastic Search and Kibana.

docker network create esnetwork
docker run --name myes --net esnetwork -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" elasticsearch:7.9.3

and Elastic Search works when I use http://localhost:9200 or http://internal-ip:9200 But when I use http://myes:9200, it just can't resolve the container name.

Thus when I run

docker run --name mykib --net esnetwork -p 5601:5601 -e “ELASTICSEARCH_HOSTS=http://myes:9200” docker.elastic.co/kibana/kibana:7.9.3

It couldn't be created because it cannot resolve myes:9200 I also tried to replace "ELASTICSEARCH_HOSTS=http://myes:9200" with localhost:9200 or internal IP instead. but nothing works. So I think my question should be how to make the container's DNS works?

CodePudding user response:

How are you resolving 'myes'? Is it mapped in hostname file and resolving to 127.0.0.1? Also, use 127.0.0.1 wherever possible as localhost could be pointing to something else and not getting resolved.

CodePudding user response:

It seems this problem doesn't arise from DNS. Both Elastic search and Kibana containers should use the fix name "elasticsearch" . so the docker command will be:

$docker network create esnetwork

$sudo vi /etc/sysctl.d/max_map_count.conf
vm.max_map_count=262144

$docker run --name elasticsearch --net esnetwork -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e 

$docker run --name kib01-test --net esnetwork -p 5601:5601 -e “ELASTICSEARCH_HOSTS=http://elasticsearch:9200” docker.elastic.co/kibana/kibana:7.9.3

Then if the terminals that run installations could be ended automatically, just close them. And restart containers from the docker desktop manager. Then everything will go smoothly.

My environment is Fedora 36, docker 20.10.18

  • Related