# Configuring APM server with env variables in docker-compose

**URL:** <https://discuss.elastic.co/t/configuring-apm-server-with-env-variables-in-docker-compose/235558>\
**Category:** APM\
**Tags:** server\
**Created:** [June 3, 2020, 1:23pm UTC](https://discuss.elastic.co/t/configuring-apm-server-with-env-variables-in-docker-compose/235558 "2020-06-03T13:23:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ffknob](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ffknob/32/37008_2.png) [@ffknob](https://discuss.elastic.co/u/ffknob)\
**Post date:** [June 3, 2020, 1:23pm UTC](https://discuss.elastic.co/t/configuring-apm-server-with-env-variables-in-docker-compose/235558/1 "2020-06-03T13:23:50Z")

</div>

Hello.

I'm trying to configure an APM server as a service in a docker-compose file. I'm doing this by setting some environment variables. This works for Elasticsearch and Kibana (although very differently, for Elasticsearch I can just use`xpack.security.enabled` but for Kibana I have to translate the vars to `XPACK_SECURITY_ENABLED`).

The thing is, I'm not letting the image's default CMD run. Instead of that, I'm running a script that waits until Elasticsearch service is up and running and then runs APM server's entrypoint. Like this:

docker-compose.yml:

```auto
  apm-server:
    container_name: apm-server_$ELASTIC_VERSION
    image: ffknob.com.br/apm-server:$ELASTIC_VERSION
    build:
      context: apm-server/
      args:
        - ELASTIC_VERSION=$ELASTIC_VERSION
    volumes:
      - shared:/shared
      - certs:/usr/share/apm-server/config/certs/:ro
    ports:
      - 8200:8200
    environment:
      - apm-server.host=apm-server:8200
      - apm-server.ssl.enaled=true
      - apm-server.ssl.key=config/certs/apm-server.key
      - apm-server.ssl.certificate=config/certs/apm-server.crt
      - apm-server.ssl.key_passphrase=$APM_SERVER_CERT_PASSWORD
      - apm-server.secret_token=$APM_SERVER_SECRET_TOKEN
      - output.elasticsearch.hosts=["elasticsearch01:9200","elasticsearch02:9200","elasticsearch03:9200"]
      - output.elasticsearch.username=apm_system
      - output.elasticsearch.password=$APM_SYSTEM_USER_PASSWORD
      - output.elasticsearch.protocol=https
    networks:
      - elastic
    depends_on:
      - elasticsearch01

```

Dockerfile:

```auto
ARG ELASTIC_VERSION
FROM docker.elastic.co/apm/apm-server:$ELASTIC_VERSION

COPY wait-for-bootstrap.sh /

CMD ["/wait-for-bootstrap.sh", "/usr/local/bin/docker-entrypoint", "-e"]

```

wait-for-bootstrap.sh:

```auto
#!/bin/sh

set -e

CMD="$@"
ELASTICSEARCH_BOOTSTRAP_READY_FILE=/shared/bootstrap/bootstrap.ready

if [[! -f ${ELASTICSEARCH_BOOTSTRAP_READY_FILE}]]
then
    >&2 echo "Elasticsearch bootstrap not ready yet. Waiting..."

    until [-f ${ELASTICSEARCH_BOOTSTRAP_READY_FILE}]
    do
      sleep 1
    done
fi

>&2 echo "Elasticsearch bootstrap finished."
exec ${CMD}

```

Result: The APMserver runs (apm-server -e), but all the environment variables I've set in the docker-compose.yml are ignored.

So, what am I doing wrong?

Thank you!

---

<div class="post-metadata">

**Author:** ![jalvz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jalvz/32/45613_2.png) [@jalvz](https://discuss.elastic.co/u/jalvz)\
**Post date:** [June 4, 2020, 7:39am UTC](https://discuss.elastic.co/t/configuring-apm-server-with-env-variables-in-docker-compose/235558/2 "2020-06-04T07:39:42Z")

</div>

Hello!

So, to run APM Server from a docker-compose file you basically need to put all that in the `command`, not in `environment`. Something like:

```auto
apm-server:
    container_name: apm-server_$ELASTIC_VERSION,
    command: [
        "apm-server", "-e",
        "-E", "apm-server.host=apm-server:8200",
        "-E", "apm-server.ssl.enaled=true",
        ...
    ],
    image: ...

```

Assuming you are running Elasticsearch from docker-compose too, you can set a condition in APM Server to wait for Elasticsearch to be ready. Like so:

```auto
depends_on: {
       elasticsearch01: {
          condition: service_healthy
       }
}

```

The health-check in Elasticsearch then, could look like this:

```auto
elasticsearch: {
      container_name: elasticsearch_$ELASTIC_VERSION,
      ....
      healthcheck: {
         interval: 10,
         retries: 10,
         test: [
          "CMD-SHELL",
          "curl -s http://localhost:9200/_cluster/health | grep -vq '\"status\":\"red\"'"
        ]
      }
}

```

Hope this helps,

Juan

---

<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 25, 2020, 3:39am UTC](https://discuss.elastic.co/t/configuring-apm-server-with-env-variables-in-docker-compose/235558/3 "2020-06-25T03:39:46Z")

</div>

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