# Setting the Elastic User Password with Dockerfile

**URL:** <https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 1:05pm UTC](https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651 "2019-05-24T13:05:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leobaiano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leobaiano/32/43704_2.png) [@leobaiano](https://discuss.elastic.co/u/leobaiano)\
**Post date:** [May 24, 2019, 1:05pm UTC](https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651/1 "2019-05-24T13:05:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ikakavas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ikakavas/32/34430_2.png) [@ikakavas](https://discuss.elastic.co/u/ikakavas)\
**Post date:** [May 24, 2019, 1:28pm UTC](https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651/2 "2019-05-24T13:28:50Z")

</div>

> [@leobaiano](#):
>
> 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

There is a number of ways to pass environment variables in a docker compose file, have you checked the [documentation](https://docs.docker.com/compose/environment-variables/) ?

---

<div class="post-metadata">

**Author:** ![leobaiano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leobaiano/32/43704_2.png) [@leobaiano](https://discuss.elastic.co/u/leobaiano)\
**Post date:** [May 24, 2019, 1:45pm UTC](https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651/3 "2019-05-24T13:45:50Z")

</div>

> [@ikakavas](#):
>
> 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

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](http://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 ☹

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 21, 2019, 1:45pm UTC](https://discuss.elastic.co/t/setting-the-elastic-user-password-with-dockerfile/182651/4 "2019-06-21T13:45:52Z")

</div>

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