# Apm-server.yml using environment variable

**URL:** <https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200>\
**Category:** APM\
**Created:** [May 18, 2020, 9:02pm UTC](https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200 "2020-05-18T21:02:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogo\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_silva/32/44993_2.png) [@Diogo\_Silva](https://discuss.elastic.co/u/Diogo_Silva)\
**Post date:** [May 18, 2020, 9:02pm UTC](https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200/1 "2020-05-18T21:02:15Z")

</div>

**Kibana version** : 7.4.2

**Elasticsearch version** : 7.4.2

**APM Server version** : apm-server-oss:7.2.1

I'm trying to create a container apm-server but when I try to use environment variable as this [https://www.elastic.co/guide/en/apm/server/current/using-environ-vars.html](https://www.elastic.co/guide/en/apm/server/current/using-environ-vars.html) and I've tried this as well [${ES\_HOST:? "[http://localhost:9200](http://localhost:9200)"}]

it return an error  
2020-05-18T20:52:17.956Z INFO instance/beat.go:292 Setup Beat: apm-server; Version: 7.2.1  
2020-05-18T20:52:17.957Z INFO instance/beat.go:385 apm-server stopped.  
2020-05-18T20:52:17.957Z ERROR instance/beat.go:877 Exiting: error initializing publisher: missing field accessin

this is my docker file

```auto

FROM docker.elastic.co/apm/apm-server-oss:7.2.1
COPY apm-server.yml /usr/share/apm-server/apm-server.yml
USER root
RUN export ES_HOSTS="host:443"
RUN chown apm-server /usr/share/apm-server/apm-server.yml
RUN chmod go-w /usr/share/apm-server/apm-server.yml
USER apm-server

```

this is my apm-server.yml

```auto
#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
  hosts: '${ES_HOSTS}'

```

---

<div class="post-metadata">

**Author:** ![gil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gil/32/41911_2.png) [@gil](https://discuss.elastic.co/u/gil)\
**Post date:** [May 18, 2020, 9:27pm UTC](https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200/2 "2020-05-18T21:27:52Z")

</div>

> [@Diogo\_Silva](#):
>
> RUN export ES\_HOSTS="host:443"

Will only export that environment variable for the duration of that `RUN`, it is not still set when the container runs.

Try [`ENV`](https://docs.docker.com/engine/reference/builder/#env) instead like:

`ENV ES_HOSTS="host:443"` or better yet, set the environment variable when starting the container.

---

<div class="post-metadata">

**Author:** ![Diogo\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_silva/32/44993_2.png) [@Diogo\_Silva](https://discuss.elastic.co/u/Diogo_Silva)\
**Post date:** [May 20, 2020, 12:06pm UTC](https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200/3 "2020-05-20T12:06:51Z")

</div>

Thanks a lot for your help

---

<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 10, 2020, 8:07am UTC](https://discuss.elastic.co/t/apm-server-yml-using-environment-variable/233200/4 "2020-06-10T08:07:04Z")

</div>

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