# APM agent not sending data with Docker

**URL:** <https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361>\
**Category:** APM\
**Tags:** go\
**Created:** [June 9, 2020, 2:29pm UTC](https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361 "2020-06-09T14:29:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dario\_Boverio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dario_boverio/32/69984_2.png) [@Dario\_Boverio](https://discuss.elastic.co/u/Dario_Boverio)\
**Post date:** [June 9, 2020, 2:29pm UTC](https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361/1 "2020-06-09T14:29:13Z")

</div>

Environment:

**Go version** : 1.14

**Kibana version** : 7.7.1

**Elasticsearch version** : 7.7.1

**APM Server version** : 7.7.1

**APM Agent language and version** : go get [go.elastic.co/apm](http://go.elastic.co/apm) and [go.elastic.co/apm/module/apmhttp](http://go.elastic.co/apm/module/apmhttp)

**Browser version** : Chrome MacOS

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: Docker-Compose

**Is there anything special in your setup?** No, just sending to the ElasticsSearch.

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

I have a docker-compose file as follow, and I export the URL APM Server to localhost (export ELASTIC\_APM\_SERVER\_URL=http://localhost:8200). When I run my Golang application, everything works fine, the agent send the data to kibana and I see the metrics in the UI.

BUT, when I uncomment my application in docker-compose (see below), just to run everything with Docker, the agent sotp sending data. I think I might be because the ELASTIC\_APM\_SERVER\_URL is set in my local machine, not inside the container. Do I have to export the ELASTIC\_APM\_SERVER\_URL in Dockerfile too? I tried but I got the same result.  
These are the docker-compose and Dockerfile files:

```auto
version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    ports:
      - 9201:9201
    networks:
      - elastic

  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
    ports:
      - 9202:9202
    networks:
      - elastic

  kib01:
    image: docker.elastic.co/kibana/kibana:7.7.1
    container_name: kib01
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: http://es01:9200
    networks:
      - elastic

  apm-server:
    image: docker.elastic.co/apm/apm-server:7.7.1
    cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"]
    cap_drop: ["ALL"]
    ports:
        - 8200:8200
    command: >
        apm-server -e
        -E apm-server.rum.enabled=true
        -E setup.kibana.host=kib01:5601
        -E setup.template.settings.index.number_of_replicas=0
        -E apm-server.kibana.enabled=true
        -E apm-server.kibana.host=kib01:5601
        -E output.elasticsearch.hosts=["es01:9200"]
    healthcheck:
        interval: 10s
        retries: 12
        test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/
    networks:
        - elastic

# proxy:
# build: .
# ports:
# - "8080:8080"
# restart: on-failure
# networks:
# - elastic

volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge

```

And the Dockerfile of my app:

```auto
FROM golang:1.14-alpine as builder

LABEL maintainer="Dario Boverio <darioboverio@gmail.com>"

RUN apk update && apk add --no-cache git

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download 

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main 

# Start a new stage from scratch
FROM alpine:latest

WORKDIR /root/

COPY --from=builder /app/main .

#I don't know if I have to do something like this 
#RUN export ELASTIC_APM_SERVER_URL=http://apm-server:8200

EXPOSE 8080

CMD ["./main"]

```

I tried everything but I couldn't figure out the problem.  
Thanks in advance.  
Best Regards,  
Dario

---

<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:** [June 9, 2020, 4:11pm UTC](https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361/2 "2020-06-09T16:11:51Z")

</div>

Welcome to the forum @Dario_Boverio!

> [@Dario\_Boverio](#):
>
> I think I might be because the ELASTIC\_APM\_SERVER\_URL is set in my local machine, not inside the container

That's exactly right. As you realized, you can set a default value for this in your Dockerfile with [`ENV`](https://docs.docker.com/engine/reference/builder/#env). In addition (or instead) you can set this environment variable when starting the container. In your `docker-compose.yml` this might look like:

```yaml
myapp:
  environment:
    ELASTIC_APM_SERVER_URL: http://apm-server:8200

```

---

<div class="post-metadata">

**Author:** ![Dario\_Boverio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dario_boverio/32/69984_2.png) [@Dario\_Boverio](https://discuss.elastic.co/u/Dario_Boverio)\
**Post date:** [June 9, 2020, 6:05pm UTC](https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361/3 "2020-06-09T18:05:34Z")

</div>

> [@gil](#):
>
> ```auto
> environment:
> ELASTIC_APM_SERVER_URL: http://apm-server:8200
> 
> ```

Thanks a lot for your answering!!! That fix the error! Now I can see the data.  
Best,  
Dario

---

<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 30, 2020, 2:05pm UTC](https://discuss.elastic.co/t/apm-agent-not-sending-data-with-docker/236361/4 "2020-06-30T14:05:41Z")

</div>

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