# What is the correct way to deploy \`Elastic Agent\` 8 via Docker?

**URL:** <https://discuss.elastic.co/t/what-is-the-correct-way-to-deploy-elastic-agent-8-via-docker/301688>\
**Category:** Beats\
**Tags:** docker, fleet, elastic-agent\
**Created:** [April 6, 2022, 1:35am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-deploy-elastic-agent-8-via-docker/301688 "2022-04-06T01:35:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![linghengqian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/linghengqian/32/103651_2.png) [@linghengqian](https://discuss.elastic.co/u/linghengqian)\
**Post date:** [April 6, 2022, 1:35am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-deploy-elastic-agent-8-via-docker/301688/1 "2022-04-06T01:35:26Z")

</div>

- I am trying to configure Elastic Stack using `docker-compose.yml` as follows, where Kibana gets the API key via `bin/elasticsearch-create-enrollment-token -s kibana`.

```nohighlight
version: "3.8"

services:
  elasticsearch-node01:
    image: elasticsearch:8.1.2
    environment:
      bootstrap.memory_lock: true
      ELASTIC_PASSWORD: "1234AF57-35CA-B2E0-BE8B-12345D5C123E"
      ES_JAVA_OPTS: "-Xms4g -Xmx4g"
    volumes:
      - elasticsearch-data01:/usr/share/elasticsearch/data
      - elasticsearch-config01:/usr/share/elasticsearch/config:rw
    ports:
      - "9200:9200"
      - "9300:9300"
    ulimits:
      memlock:
        soft: -1
        hard: -1
  kibana-node01:
    image: kibana:8.1.2
    environment:
      XPACK_SECURITY_ENCRYPTIONKEY: fc12345ea223eb1234dac7b1234ac62e
      XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: 1bb85c4e9ed1c36ae4a8ead1234567f1
      XPACK_REPORTING_ENCRYPTIONKEY: af5cbdd2e2f4da20a72f60f1e123456f
    ports:
      - "5601:5601"
    volumes:
      - kibana-data01:/usr/share/kibana/data
      - kibana-config01:/usr/share/kibana/config

volumes:
  elasticsearch-data01:
    driver: local
  elasticsearch-config01:
    driver: local
  kibana-data01:
    driver: local
  kibana-config01:
    driver: local

```

- After the normal startup, I entered the integration page of Fleet, clicked `Create policy` to create `Fleet Server policy 1`, and added `Fleet Server host` as `http://elastic-agent-node01:8220` (mentioned later ). At this time by ` Generate a service token` generates a `service token`, `AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE2NDkyMDgzNzg0MzI6dGdxV0kzRWJSSk9RY3ppRVo3R3hwQQ`.

- 

- Then get `Enrollment tokens` at `http://localhost:5601/app/fleet/enrollment-tokens` as `Ymh4M19IOEJFRUlyYW43dUpRRzI6N0pDeVNkaFpTRFdoNU1HTWFGaEZHZw==`.

- 

- According to [Run Elastic Agent in a container | Fleet and Elastic Agent Guide [8.1] | Elastic](https://www.elastic.co/guide/en/fleet/8.1/elastic-agent-container.html) , I updated `docker-compose.yml` as follows, and then executed `docker compose pull` and `docker compose up -d` to start `Elastic Agent`.

```nohighlight
version: "3.8"

services:
  elasticsearch-node01:
    image: elasticsearch:8.1.2
    environment:
      bootstrap.memory_lock: true
      cluster.name: "sg8000-elasticsearch"
      ELASTIC_PASSWORD: "1234AF57-35CA-B2E0-BE8B-12345D5C123E"
      ES_JAVA_OPTS: "-Xms4g -Xmx4g"
    volumes:
      - elasticsearch-data01:/usr/share/elasticsearch/data
      - elasticsearch-config01:/usr/share/elasticsearch/config:rw
    ports:
      - "9200:9200"
      - "9300:9300"
    ulimits:
      memlock:
        soft: -1
        hard: -1
  kibana-node01:
    image: kibana:8.1.2
    environment:
      XPACK_SECURITY_ENCRYPTIONKEY: fc12345ea223eb1234dac7b1234ac62e
      XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: 1bb85c4e9ed1c36ae4a8ead1234567f1
      XPACK_REPORTING_ENCRYPTIONKEY: af5cbdd2e2f4da20a72f60f1e123456f
    ports:
      - "5601:5601"
    volumes:
      - kibana-data01:/usr/share/kibana/data
      - kibana-config01:/usr/share/kibana/config
  elastic-agent-node01:
    image: elastic/elastic-agent:8.1.2
    restart: always
    user: root
    environment:
      FLEET_ENROLLMENT_TOKEN: "Ymh4M19IOEJFRUlyYW43dUpRRzI6N0pDeVNkaFpTRFdoNU1HTWFGaEZHZw=="
      FLEET_ENROLL: 1
      FLEET_URL: http://elastic-agent-node01:8220
      FLEET_SERVER_ENABLE: true
      FLEET_SERVER_ELASTICSEARCH_HOST: http://elasticsearch-node01:9200
      FLEET_SERVER_SERVICE_TOKEN: "AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE2NDkyMDgzNzg0MzI6dGdxV0kzRWJSSk9RY3ppRVo3R3hwQQ"

volumes:
  elasticsearch-data01:
    driver: local
  elasticsearch-config01:
    driver: local
  kibana-data01:
    driver: local
  kibana-config01:
    driver: local

```

- Then I got a series of ERRORs starting up in the logs of the Elastic Agent in Docker Desktop. At the same time Kibana did not get Fleet's registration information.

- 

- 

- I'm confused how to configure `Elastic Agent`, hope some friends can help.

---

<div class="post-metadata">

**Author:** ![linghengqian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/linghengqian/32/103651_2.png) [@linghengqian](https://discuss.elastic.co/u/linghengqian)\
**Post date:** [April 7, 2022, 10:54am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-deploy-elastic-agent-8-via-docker/301688/2 "2022-04-07T10:54:47Z")

</div>

I realize the key point of the issue, this disscus I will mark as resolved, and the documentation issue can be tracked at [Add introduction to the `FLEET_SERVER_ELASTICSEARCH_CA_TRUSTED_FINGERPRINT` environment variable in documentation · Issue #311 · elastic/elastic-agent · GitHub](https://github.com/elastic/elastic-agent/issues/311) and [Add instructions to what need to `volumes` in the documentation for containerized deployments · Issue #313 · elastic/elastic-agent (github.com)](https://github.com/elastic/elastic-agent/issues/313).

---

<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:** [May 5, 2022, 12:55pm UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-deploy-elastic-agent-8-via-docker/301688/3 "2022-05-05T12:55:23Z")

</div>

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