Elasticsearch on another port?

Hi,

I’m trying to run Elasticsearch on a different port than the default 9200 one ( I’m using Gitlab that is already using it halas :sweat_smile: ), but can’t make it work, here is my configuration :

Parameters.php
“es” => [
“host” => “elasticsearch:9201”

docker-compose.yml
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
environment:
cluster.name=docker-cluster
bootstrap.memory_lock=true
“ES_JAVA_OPTS=-Xms512m -Xmx512m”
ulimits:
memlock:
soft: -1
hard: -1
volumes:
./docker-data/es_twake:/usr/share/elasticsearch/data
ports:
9201:9201

PHP Logs :

Blockquote
php_1 | :hourglass_flowing_sand:Waiting for ElasticSearch connection
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 | … not found, retry in 5 seconds (timeout 180s)
php_1 |
php_1 | :boom: Unable to join ElasticSearch !

Any idea on what I’m missing ?

Regards,

Valzul

Hello, to change elasticsearch port, you must understand that Docker has internal ports and public ports.
In your case you don’t want to change the internal port.

In your case you need to:

  1. docker-compose.yml (docker ports mapping works like this: external:internal)
ports:
    9201:9200
  1. Let Parameters.php untouched. (as php runs in the same docker as elasticsearch and will so use internal ports)

You can also just remove the port mapping in docker-compose.yml, it’s only of use if you want to curl localhost:9200.

I don’t know if my explanation is clear enough, but the idea is tha docker works like a subnetwork, with its own ports :slight_smile:

Thanks for the explanation on docker ! :smile:

I changed my elasticsearch configuration in docker-compose.yml to be :

ports:
    9201:9200

and rolled back Parameters.php to be :

“es” => [
   “host” => “elasticsearch:9200”

then ran the set of commands :

docker-compose stop
docker-compose rm ( just to be sure )
docker-compose pull
docker-compose up -d

Yet got the same result, unable to join ElasticSearch …
would you be kind enough to test this configuration on your side if possible ?

Regards,

Valzul

I didn’t forget your request, when I have time I’ll try your configuration and tell you :+1:
Can you just tell me what are the logs of elasticsearch ?
docker-compose logs -f --tail 100 elasticsearch

Here is the beast :

Attaching to twake_elasticsearch_1
e[36melasticsearch_1  |e[0m OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
e[36melasticsearch_1  |e[0m [2020-07-23T16:16:32,465][INFO ][o.e.n.Node               ] [] initializing ...
e[36melasticsearch_1  |e[0m [2020-07-23T16:16:32,474][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
e[36melasticsearch_1  |e[0m org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m Caused by: java.lang.IllegalStateException: Failed to create node environment
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.node.Node.<init>(Node.java:277) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	... 6 more
e[36melasticsearch_1  |e[0m Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
e[36melasticsearch_1  |e[0m 	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
e[36melasticsearch_1  |e[0m 	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
e[36melasticsearch_1  |e[0m 	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
e[36melasticsearch_1  |e[0m 	at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385) ~[?:?]
e[36melasticsearch_1  |e[0m 	at java.nio.file.Files.createDirectory(Files.java:682) ~[?:?]
e[36melasticsearch_1  |e[0m 	at java.nio.file.Files.createAndCheckIsDirectory(Files.java:789) ~[?:?]
e[36melasticsearch_1  |e[0m 	at java.nio.file.Files.createDirectories(Files.java:775) ~[?:?]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:207) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.node.Node.<init>(Node.java:274) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.3.jar:6.4.3]
e[36melasticsearch_1  |e[0m 	... 6 more
e[36mtwake_elasticsearch_1 exited with code 1
e[0m

Looks like a write access is not given, as AccessDeniedException or createDirectory would suggest, in :

/usr/share/elasticsearch/data/nodes

Regards,

Valzul

Ok I have a fast fix if you want (I didn’t found a solution yet)
I suppose docker-data/es_twake is empty.
Just do a sudo chmod 777 docker-data/es_twake/ and restart elasticsearch.
If ES works, stop and up everything again, it should work.

I will investigate the bug in the next days! :mag_right:

Hi,

Thanks for the quick fix :+1:

Regards,

Valzul