# Elastic Agent using Docker: "failed version compatibility check with elasticsearch: dial tcp localhost:9200: connect: connection"

**URL:** <https://discuss.elastic.co/t/elastic-agent-using-docker-failed-version-compatibility-check-with-elasticsearch-dial-tcp-localhost-connect-connection/356003>\
**Category:** Elastic Agent\
**Created:** [March 22, 2024, 3:40pm UTC](https://discuss.elastic.co/t/elastic-agent-using-docker-failed-version-compatibility-check-with-elasticsearch-dial-tcp-localhost-connect-connection/356003 "2024-03-22T15:40:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NikoCosmico01](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@NikoCosmico01](https://discuss.elastic.co/u/NikoCosmico01)\
**Post date:** [March 22, 2024, 3:40pm UTC](https://discuss.elastic.co/t/elastic-agent-using-docker-failed-version-compatibility-check-with-elasticsearch-dial-tcp-localhost-connect-connection/356003/1 "2024-03-22T15:40:59Z")

</div>

Hi,  
I am struggling adding elastic agent on docker. All the times I try to docker run the agent this error appears:  
\< "failed version compatibility check with elasticsearch: dial tcp localhost:9200: connect: connection refused" \>

The command used is:

docker run --env FLEET\_SERVER\_ENABLE=true --env FLEET\_SERVER\_SERVICE\_TOKEN=[TOKEN] --env FLEET\_SERVER\_POLICY\_ID=[POLICY-ID] --env FLEET\_SERVER\_ELASTICSEARCH\_HOST=localhost --env FLEET\_INSECURE=true -p 8220:8220 --rm [docker.elastic.co/beats/elastic-agent:8.12.2](http://docker.elastic.co/beats/elastic-agent:8.12.2)

I cannot write properly the hosts due to post url restriction but the above localhost is http.  
Unable to load docker-compose.yml for the same reason

Answering to @cmacknz from GitHub issue port 9200 should still be exposed in the docker-compose file. Do I need to use "expose" instead of "ports" ? By the way I am able to curl http:// localhost:9200 from the host machine and, even receiving an empty response my action is logged by Elasticsearch. When I try to docker run the elastic agent nothing is logged.

---

<div class="post-metadata">

**Author:** ![cmacknz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cmacknz/32/103773_2.png) [@cmacknz](https://discuss.elastic.co/u/cmacknz)\
**Post date:** [March 22, 2024, 4:00pm UTC](https://discuss.elastic.co/t/elastic-agent-using-docker-failed-version-compatibility-check-with-elasticsearch-dial-tcp-localhost-connect-connection/356003/2 "2024-03-22T16:00:47Z")

</div>

If you start a shell inside your agent container with `docker run --entrypoint=/bin/bash -it docker.elastic.co/beats/elastic-agent:8.12.2` does `curl localhost:9200` succeed?

Likely that is hitting the localhost of the container, and not the localhost of your host machine. The special hostname `host.docker.internal` should resolve to the host machines local address. If `curl host.docker.internal:9200` succeeds that is the problem.

---

<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:** [April 19, 2024, 4:01pm UTC](https://discuss.elastic.co/t/elastic-agent-using-docker-failed-version-compatibility-check-with-elasticsearch-dial-tcp-localhost-connect-connection/356003/3 "2024-04-19T16:01:47Z")

</div>

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