2

As showed bellow, I can reach my local docker exposing a elasticsearch port when I tried curl localhost (from Browser also) but it fails when I try to connect from another container. I read several questions with same issue (connection refused) from both (curl and another container) but in my case I only have issue from another container.

C:\Dockers\megalog-try-1>docker run docker.elastic.co/beats/filebeat:7.5.2 setup -E setup.kibana.host=localhost:5601 -E output.elasticsearch.hosts=["localhost:9200"]
Exiting: Couldn't connect to any of the configured Elasticsearch hosts. Errors: [Error connection to Elasticsearch http://localhost:9200: Get http://localhost:9200: dial tcp [::1]:9200: connect: cannot assign requested address]

C:\Dockers\megalog-try-1>curl localhost:9200
{
  "name" : "f225ebd4879e",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "YyfW8X5DRt2RTacNYlZ3jA",
  "version" : {
    "number" : "7.5.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
    "build_date" : "2020-01-15T12:11:52.313576Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

C:\Dockers\megalog-try-1>docker-compose ps
            Name                           Command               State                            Ports                 
---------------------------------------------------------------------------------------------------------------------------------
megalog-try-1_elasticsearch_1   /usr/local/bin/docker-entr ...   Up      0.0.0.0:9200->9200/tcp, 9300/tcp               
megalog-try-1_filebeat_1        /usr/local/bin/docker-entr ...   Up                                                     
megalog-try-1_kafka1_1          /etc/confluent/docker/run        Up      0.0.0.0:9092->9092/tcp                         
megalog-try-1_kafka2_1          /etc/confluent/docker/run        Up      0.0.0.0:9093->9092/tcp                         
megalog-try-1_kafka3_1          /etc/confluent/docker/run        Up      0.0.0.0:9094->9092/tcp                         
megalog-try-1_kibana_1          /usr/local/bin/dumb-init - ...   Up      0.0.0.0:5601->5601/tcp                         
megalog-try-1_logstash_1        /usr/local/bin/docker-entr ...   Up      5044/tcp, 0.0.0.0:7777->7777/tcp, 0.0.0.0:9600->9600/tcp
megalog-try-1_zoo1_1            /etc/confluent/docker/run        Up      0.0.0.0:2181->2181/tcp, 2888/tcp, 3888/tcp     
megalog-try-1_zoo2_1            /etc/confluent/docker/run        Up      0.0.0.0:2182->2181/tcp, 2888/tcp, 3888/tcp     
megalog-try-1_zoo3_1            /etc/confluent/docker/run        Up      0.0.0.0:2183->2181/tcp, 2888/tcp, 3888/tcp     

C:\Dockers\megalog-try-1> 

*** edit 1

C:\Dockers\megalog-try-1>docker run -it docker.elastic.co/beats/filebeat:7.5.2 setup -E setup.kibana.host=192.168.44.209:5601 -E output.elasticsearch.hosts=["192.168.44.209:9200"] bash
Exiting: 503 Service Unavailable: {"error":{"root_cause":[{"type":"failed_to_commit_cluster_state_exception","reason":"publication failed"}],"type":"master_not_discovered_exception","reason":"FailedToCommitClusterStateException[publication failed]; nested: AlreadyClosedException[Underlying file changed by an external force at 1970-01-01T00:00:00Z, (lock=NativeFSLock(path=/usr/share/elasticsearch/data/nodes/0/node.lock,impl=sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid],creationTime=2020-02-06T19:25:40.498294Z))];","caused_by":{"type":"failed_to_commit_cluster_state_exception","reason":"publication failed","caused_by":{"type":"already_closed_exception","reason":"Underlying file changed by an external force at 1970-01-01T00:00:00Z, (lock=NativeFSLock(path=/usr/share/elasticsearch/data/nodes/0/node.lock,impl=sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid],creationTime=2020-02-06T19:25:40.498294Z))"}}},"status":503}

C:\Dockers\megalog-try-1>docker run docker.elastic.co/beats/filebeat:7.5.2 setup -E setup.kibana.host=192.168.44.209:5601 -E output.elasticsearch.hosts=["192.168.44.209:9200"]
Exiting: 503 Service Unavailable: {"error":{"root_cause":[{"type":"master_not_discovered_exception","reason":null}],"type":"master_not_discovered_exception","reason":null},"status":503}

C:\Dockers\megalog-try-1>
Jim C
  • 3,957
  • 25
  • 85
  • 162

1 Answers1

3

Docker creates containers that are selfcontained units that has its own IP within a virtual switch.

By binding ports you make your docker (which sits on your actual local machine) to expose (route) incomming requests to a specific port to a specific container within this virtual network.

When you start your SECOND container, by telling it that elasticsearch sits at localhost:9000 you are telling it that it sists actually within the same container (container 2) which is not true.

You need to provide to the SECOND container the ip of the container where elasticsearch sits (or in this case you can even provide the ip of your machine as ports are binded) but for shure you can not say to the container 2 to connect to localhost.

Let me know how can I make this answer more clear.

Newbie
  • 4,462
  • 11
  • 23
  • I got (lock=NativeFSLock(path=/usr/share/elasticsearch/data/nodes/0/node.lock.... I added above entire conlose logs – Jim C Feb 06 '20 at 20:25
  • 1
    Have you tried with the actual containers IP, not familiar with `filebeat` but it looks like it is quit close entangled with ElasticSearch, so it may need direct access to the server, weather trying to connect trough the outer host may cause some troubles. See https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host – Newbie Feb 06 '20 at 20:32
  • I follow your link suggestion and use docker inspect to pick up current elasticsearch and kibana ip. I am still not able to connect. Here are the logs: C:\Dockers\megalog-try-1>docker run docker.elastic.co/beats/filebeat:7.5.2 setup -E setup.kibana.host=172.28.0.6:5601 -E output.elasticsearch.hosts=["172.28.0.2:9200"] Exiting: Couldn't connect to any of the configured Elasticsearch hosts. Errors: [Error connection to Elasticsearch http://172.28.0.2:9200: Get http://172.28.0.2:9200: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)] – Jim C Feb 06 '20 at 21:20
  • Well, it seems if I use my laptop IP I move forward. Here is the log using my Ethernet Adapter IP instead of the ip from docker inspect: C:\Dockers\megalog-try-1>docker run docker.elastic.co/beats/filebeat:7.5.2 setup -E setup.kibana.host=192.168.44.209:5601 -E output.elasticsearch.hosts=["192.168.44.209:9200"] Index setup finished. Loading dashboards (Kibana must be running and reachable) Loaded dashboards Loaded machine learning job configurations Loaded Ingest pipelines C:\Dockers\megalog-try-1> – Jim C Feb 06 '20 at 21:25