Setting the Elastic User Password with Dockerfile

I created a docker-compose.yml with:

   build:
       context:.
       dockerfile: ./Dockerfile

The problem is that when I use Dockerfile for the image it does not accept the environment so I can not set the password of the elastic user through

- ELASTIC_PASSWORD=password

I need my script to be complete, that when running docker-compose-up it will start the container and then change the elastic password, for that I wrote a .sh, although I do not know if it is the best way, but I do not know how make .sh run after the container is running.

Can anyone help me with this? It does not necessarily have to be through the .sh I created, I just need the password to be set automatically.

There is a number of ways to pass environment variables in a docker compose file, have you checked the documentation ?

Thanks for the answer @ikakavas

I do not think I've expressed myself properly, I'm also very good at it, let me try to improve.

If I have it in my docker-compose.yml:

version: '2.2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.7.1
    container_name: elasticsearch
    environment:
      - "ELASTIC_PASSWORD = test123"

But if I have it in my docker-compose.yml:
version: '2.2'
services:
elasticsearch:
# image: docker.elastic.co/elasticsearch/elasticsearch:6.7.1
build:
context:.
dockerfile: ./Dockerfile
container_name: elasticsearch
environment:
- "ELASTIC_PASSWORD = test123"

It does not work because I should set the ELASTIC_PASSWORD in Dockerfile and not in docker-compose.

My Dockerfile only has:

FROM elasticsearch: 6.7.1
# copy some files as elasticsearch.yml
CMD ["elasticsearch"]

I can do everything work locally on my machine using only docker-compose.yml, however I need Dockerfile to send it to heroku :frowning:

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