# Fleet & Docker - How to maintain state?

**URL:** <https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156>\
**Category:** Elastic Agent\
**Tags:** fleet\
**Created:** [August 1, 2022, 7:08pm UTC](https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156 "2022-08-01T19:08:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DefensiveDepth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defensivedepth/32/110034_2.png) [@DefensiveDepth](https://discuss.elastic.co/u/DefensiveDepth)\
**Post date:** [August 1, 2022, 7:08pm UTC](https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156/1 "2022-08-01T19:08:33Z")

</div>

I am running Fleet 8.3.3 in a Docker Container, using the docs found [here](https://www.elastic.co/guide/en/fleet/current/elastic-agent-container.html):

It appears that every time the container is destroyed and a new one created, a new Fleet server is registered, even if I set the container `hostname` to the same string (`test02` in this case):

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/7/77c871ba2a54866a3ee9d05fe31cb42a557f1537.png)

How do I set this up so that a new Fleet instance is not created every time the container is rebuilt?

---

<div class="post-metadata">

**Author:** ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)\
**Post date:** [August 1, 2022, 8:36pm UTC](https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156/2 "2022-08-01T20:36:52Z")

</div>

I believe if you don't want things to change on every startup, you need to persist the data directory (`/opt/Elastic/Agent/`) - [Installation layout | Fleet and Elastic Agent Guide [8.3] | Elastic](https://www.elastic.co/guide/en/fleet/8.3/installation-layout.html). Note, you can also set an auto unenroll timeout, so if you don't want to persist the directory, you can just have the old ones unenroll themselves after a period of time.

---

<div class="post-metadata">

**Author:** ![DefensiveDepth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defensivedepth/32/110034_2.png) [@DefensiveDepth](https://discuss.elastic.co/u/DefensiveDepth)\
**Post date:** [August 2, 2022, 11:55am UTC](https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156/3 "2022-08-02T11:55:05Z")

</div>

Thanks @BenB196 - I tried to bind `/opt/Elastic/Agent` to the host filesystem, but that didnt appear to change anything. Digger deeper into the container I saw `/usr/share/elastic-agent/state` - Once I bound that to the host filesystem, I was able to maintain state outside of the container.

This does not appear to be documented anywhere.

---

<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:** [August 30, 2022, 11:55am UTC](https://discuss.elastic.co/t/fleet-docker-how-to-maintain-state/311156/4 "2022-08-30T11:55:31Z")

</div>

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