Setting variable http.port

I need to set the http port dynamically using an environment variable to run my docker container on heroku, for that purpose I added the code below in my Dockerfile:

CMD ["elasticsearch","-Ehttp.port=$PORT"]

It seems that heroku does the job of passing the door through the environment variable because I get the message below in the log:

Starting process with command elasticsearch -Ehttp.port \ = \ 10323`

But soon after I get the error:

org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: invalid port range: $ PORT

My Dockerfile is simple, just create an image from elasticsearch: 6.7.1 and copy a new jvm.options and elasticsearch.yml to customize, so I do not think it's necessary to copy the code here, but I'll do it if I have to.

Has anyone ever had anything like this or do you have any idea what I might be doing wrong?

Thank you very much.

Hi @leobaiano,

Could you try using ${PORT} instead, please?

Cheers,
Luiz Santos

@luiz.santos,

I managed to resolve this issue, but then the elasticsearch stopped responding unexpectedly and the heroku ended the process.

The question here is that if you use the command in a list ([...]) the variable $ PORT is not interpreted, so the errorinvalid port range: $ PORT, to solve it just remove the list so :

CMD elasticsearch -Ettp.port = $ PORT

Even using {$ PORT} within the list would not interpret.

I still can not run elasticsearch nor kibana on heroku via Dockerfile, I always encounter one of its errors. With the kibana now it is giving timeout in the response of the door, even I defining the door with the variable of their environment.

Thank you very much for the answer, if anyone can close the topic, because I can not.

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