# NATS Integration with an Elastic Agent Container

**URL:** <https://discuss.elastic.co/t/nats-integration-with-an-elastic-agent-container/378092>\
**Category:** Elastic Agent\
**Created:** [May 13, 2025, 3:40pm UTC](https://discuss.elastic.co/t/nats-integration-with-an-elastic-agent-container/378092 "2025-05-13T15:40:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wpm/32/110146_2.png) [@wpm](https://discuss.elastic.co/u/wpm)\
**Post date:** [May 13, 2025, 3:40pm UTC](https://discuss.elastic.co/t/nats-integration-with-an-elastic-agent-container/378092/1 "2025-05-13T15:40:20Z")

</div>

I want to log all the NATS messages handled by a NATS server to a Elasticsearch instance. I want to do it in the following manner:

- Using serverless cloud instances of Elasticsearch and Kibana
- Using Elastic Agent and Fleet
- Using the NATS Integration
- Running the NATS server on my laptop
- Running everything local to my laptop—NATS server, Elastic Agent—in Docker containers

This seems to be the preferred way to set things up, or at least a reasonable way. I am using the [Run Elastic Agent in a container](https://www.elastic.co/docs/reference/fleet/elastic-agent-container) documentation as a guide.

I have created a serverless cloud project called "[Werewolf](https://cloud.elastic.co/projects/elasticsearch/cff700b63ff84d46ae64e13f00f616f5)". On my laptop I have the following `docker-compose.yml`.

```yml
services:
  nats-server:
    image: nats:2.9.15
    environment:
      - NATS_HOST=nats-server
    ports:
      - "4222:4222" # Client connections
      - "8222:8222" # HTTP monitoring
      - "8080:8080" # Websocket
    volumes:
      - ./nats-server.conf:/nats-server.conf
    command: "--config /nats-server.conf"

  elastic-agent:
    image: docker.elastic.co/elastic-agent/elastic-agent:9.0.1
    user: root
    restart: always
    environment:
      - FLEET_ENROLLMENT_TOKEN= **********
      - FLEET_ENROLL=1
      - FLEET_URL=https://cff700b63ff84d46ae64e13f00f616f5.fleet.us-east-1.
      - FLEET_SERVER_ENABLE=true
      - FLEET_SERVER_ELASTICSEARCH_HOST=https://werewolf-cff700.es.us-east-1.aws.elastic.cloud
      - FLEET_SERVER_SERVICE_TOKEN= **********

```

I got my various Elastic Agent environment values from the following places in the Elasticcloud UI:

- `FLEET_ENROLLMENT_TOKEN`: Project Werewolf \> Fleet \> Enrollment Tokens
- `FLEET_URL`: Project Werewolf \> Fleet \> Settings \> Fleet Server Hosts
- `FLEET_SERVER_ELASTICSEARCH_HOST`: Project Werewolf \> Connection alias
- `FLEET_SERVER_SERVICE_TOKEN`: _No idea. None of this is clearly documented so I mostly just search randomly through the UI for things and sometimes I can't remember where I found a particular key._

When I start the containers with `docker compose up`, the NATS container works fine, but the Elastic Agent container doesn't. It produces an overwhelming amount of logging, but here are errors that seem relevant.

```auto
...
2025-05-13T14:44:23.915183596Z {"log.level":"error","@timestamp":"2025-05-13T14:44:23.914Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).watchRuntimeComponents","file.name":"coordinator/coordinator.go","file.line":714},"message":"Unit state changed fleet-server-default (STARTING->FAILED): Error - failed version compatibility check with elasticsearch: dial tcp 34.193.206.135:9200: i/o timeout","log":{"source":"elastic-agent"},"component":{"id":"fleet-server-default","state":"HEALTHY"},"unit":{"id":"fleet-server-default","type":"output","state":"FAILED","old_state":"STARTING"},"ecs.version":"1.6.0"}
2025-05-13T14:44:23.915404721Z {"log.level":"error","@timestamp":"2025-05-13T14:44:23.915Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).watchRuntimeComponents","file.name":"coordinator/coordinator.go","file.line":714},"message":"Unit state changed fleet-server-default-fleet-server (STARTING->FAILED): Error - failed version compatibility check with elasticsearch: dial tcp 34.193.206.135:9200: i/o timeout","log":{"source":"elastic-agent"},"component":{"id":"fleet-server-default","state":"HEALTHY"},"unit":{"id":"fleet-server-default-fleet-server","type":"input","state":"FAILED","old_state":"STARTING"},"ecs.version":"1.6.0"}
2025-05-13T14:44:35.927477921Z {"log.level":"error","@timestamp":"2025-05-13T14:44:35.926Z","message":"failed to fetch elasticsearch version","component":{"binary":"fleet-server","dataset":"elastic_agent.fleet_server","id":"fleet-server-default","type":"fleet-server"},"log":{"source":"fleet-server-default"},"ecs.version":"1.6.0","service.name":"fleet-server","service.type":"fleet-server","error.message":"dial tcp 34.193.206.135:9200: i/o timeout","ecs.version":"1.6.0"}
2025-05-13T14:44:35.927738504Z {"log.level":"error","@timestamp":"2025-05-13T14:44:35.926Z","message":"Fleet Server failed","component":{"binary":"fleet-server","dataset":"elastic_agent.fleet_server","id":"fleet-server-default","type":"fleet-server"},"log":{"source":"fleet-server-default"},"error.message":"failed version compatibility check with elasticsearch: dial tcp 34.193.206.135:9200: i/o timeout","ecs.version":"1.6.0","service.name":"fleet-server","service.type":"fleet-server","ecs.version":"1.6.0"}
2025-05-13T14:44:35.928394504Z {"log.level":"error","@timestamp":"2025-05-13T14:44:35.927Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).watchRuntimeComponents","file.name":"coordinator/coordinator.go","file.line":714},"message":"Unit state changed fleet-server-default-fleet-server (STARTING->FAILED): Error - failed version compatibility check with elasticsearch: dial tcp 34.193.206.135:9200: i/o timeout","log":{"source":"elastic-agent"},"component":{"id":"fleet-server-default","state":"HEALTHY"},"unit":{"id":"fleet-server-default-fleet-server","type":"input","state":"FAILED","old_state":"STARTING"},"ecs.version":"1.6.0"}
...

```

This repeats over and over.

I don't know why a "version compatibility check" is failing since I'm using the latest version of everything. Nothing in the documentation gives me an indication of what might be going on. I have no idea what to do at this point.
