Mapping ElasticSearch Port with ports: 92xx:9200 in Docker


(CR) #1

Is it possible to map the default port for an ElasticSearch docker container from 9200 to 92XX (i.e. 9222) or some other port using -

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
...
ports:

  • 92xx:9200

When I attempt to do this and connect using Kibana, Kibana will only connect if configured on port 9200, i.e. ->
ELASTICSEARCH_URL=http://elasticsearch:9200

and
ELASTICSEARCH_URL=http://elasticsearch:96xx
does not work.

docker container exec -i kibana curl elasticsearch:9200/_cat/health
returns a valid connection, even though the port should be remapped to 96xx.

docker container exec -i kibana curl elasticsearch:92xx/_cat/health
returns invalid connection data.

I have used docker container stop and rm to remove all prior container instances.


(Jen Huang) #2

By default, Elasticsearch docker reserves the ports 9200 and 9300. Example base Docker Compose file showing both ports.

To change the ports (to 9299 and 9399, for example), add:

    ports:
      - "9299:9200"
      - "9399:9300"

which maps custom outside port to regular ES inside port.

Then change Kibana configuration accordingly:

    environment:
      ELASTICSEARCH_URL: http://elasticsearch:9299

(CR) #3

I am getting the "No living connection" error at Kibana when I try to do the configuration according to your example and ES is not accessible from a browser at localhost:9299


(Jen Huang) #4

Could you share your entire docker-compose.yml file?


(CR) #5
version: "3"

volumes:
elasticsearch-test-vol:

networks:
elasticsearch-test-net:

services:

elasticsearch-test-624-service:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    container_name: elasticsearch-test-624
    restart: always
    networks:
    - elasticsearch-test-net
    environment:
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - xpack.security.enabled=true
    ulimits:
        memlock:
            soft: -1
            hard: -1
    ports:
    - "9699:9699"
    expose:
    - "9699"
    volumes:
    - elasticsearch-test-vol:/usr/share/elasticsearch/data

kibana-test-624-service:
    image: docker.elastic.co/kibana/kibana:6.2.4
    container_name: kibana-test-624
    hostname: kibana
    restart: always
    networks:
    - elasticsearch-test-net
    environment:
    - SERVER_NAME=kibana.localhost
    - ELASTICSEARCH_URL=http://elasticsearch-test-624:9699
    - ELASTICSEARCH_USERNAME=elastic
    - ELASTICSEARCH_HOST=elasticsearch-test-624
    - ELASTICSEARCH_PORT=9699
    - ELASTIC_PWD=changeme
    - KIBANA_PWD=changeme
    ports:
    - "5699:5601"
    expose:
    - "5624"
    links:
    - elasticsearch-test-624-service
    depends_on:
    - elasticsearch-test-624-service

(CR) #6

kibana-test-624 | {"type":"log","@timestamp":"2018-05-29T14:11:48Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
kibana-test-624 | {"type":"log","@timestamp":"2018-05-29T14:11:51Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch-test-624:9699/"}


(Jen Huang) #7

Apologies for the late follow up. My previous post had incorrect information with regards to the ports. The mapping should be HOST:CONTAINER. I have edited my post as well.

So for your Elasticsearch service, it should be:

ports:
    - "9699:9200"

The rest of the configuration looks good.

(More about ports and expose: https://stackoverflow.com/a/40801773)


(CR) #8

I am getting errors when I try the following yml:

version: "3"

volumes:
elasticsearch-test-vol:

networks:
elasticsearch-test-net:

services:

elasticsearch-test-624-service:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    container_name: elasticsearch-test-624
    restart: always
    networks:
        - elasticsearch-test-net
    environment:
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - xpack.security.enabled=true
    ulimits:
        memlock:
            soft: -1
            hard: -1
    ports:
    - "9699:9200"
    expose:
    - "9699"
    volumes:
    - elasticsearch-test-vol:/usr/share/elasticsearch/data

kibana-test-624-service:
    image: docker.elastic.co/kibana/kibana:6.2.4
    container_name: kibana-test-624
    hostname: kibana
    restart: always
    networks:
    - elasticsearch-test-net
    environment:
    - SERVER_NAME=kibana.localhost
    - ELASTICSEARCH_URL=http://elasticsearch-test-624:9699
    - ELASTICSEARCH_USERNAME=elastic
    - ELASTICSEARCH_HOST=elasticsearch-test-624
    - ELASTICSEARCH_PORT=9699
    - ELASTIC_PWD=changeme
    - KIBANA_PWD=changeme
    - xpack.security.enabled=true
    ports:
    - "5699:5601"
    expose:
    - "5699"
    depends_on:
    - elasticsearch-test-624-service

The error messages are as follows:
Kibana console:

Login is currently disabled. Administrators should consult the Kibana logs for more details.

Logs to stdout:

kibana-test-624                   | {"type":"log","@timestamp":"2018-06-11T18:53:29Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch-test-624:9699/"}
kibana-test-624                   | {"type":"log","@timestamp":"2018-06-11T18:53:29Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}

$ docker-compose ps
     Name                   Command           State           Ports         
--------------------------------------------------------------------------------
elasticsearch-test-624   /usr/local/bin/docker-   Up      0.0.0.0:9699->9200/tcp
                     entr ...                         , 9300/tcp, 9699/tcp  
kibana-test-624          /bin/bash                Up      0.0.0.0:5699->5601/tcp
                     /usr/local/bin/k ...             , 5699/tcp

(CR) #9

As a point of reference, the identical YML with the default port mapping to 9200:9200 works without errors reported... I am explicitly trying to get the port mappings working in this case.

version: "3"

volumes:
elasticsearch-test-vol:

networks:
elasticsearch-test-net:

services:

elasticsearch-test-624-service:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    container_name: elasticsearch-test-624
    restart: always
    networks:
        - elasticsearch-test-net
    environment:
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - xpack.security.enabled=true
    ulimits:
        memlock:
            soft: -1
            hard: -1
    ports:
    - "9200:9200"
    expose:
    - "9200"
    volumes:
    - elasticsearch-test-vol:/usr/share/elasticsearch/data

kibana-test-624-service:
    image: docker.elastic.co/kibana/kibana:6.2.4
    container_name: kibana-test-624
    hostname: kibana
    restart: always
    networks:
    - elasticsearch-test-net
    environment:
    - SERVER_NAME=kibana.localhost
    - ELASTICSEARCH_URL=http://elasticsearch-test-624:9200
    - ELASTICSEARCH_USERNAME=elastic
    - ELASTICSEARCH_HOST=elasticsearch-test-624
    - ELASTICSEARCH_PORT=9200
    - ELASTIC_PWD=changeme
    - KIBANA_PWD=changeme
    - xpack.security.enabled=true
    ports:
    - "5699:5601"
    expose:
    - "5699"
    depends_on:
    - elasticsearch-test-624-service

(system) #10

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.