# Elastic Agent - State persistence in Docker

**URL:** <https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352>\
**Category:** Beats\
**Tags:** docker, elastic-agent\
**Created:** [January 14, 2022, 3:03am UTC](https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352 "2022-01-14T03:03:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bar0n36](https://avatars.discourse-cdn.com/v4/letter/b/dbc845/32.png) [@bar0n36](https://discuss.elastic.co/u/bar0n36)\
**Post date:** [January 14, 2022, 3:03am UTC](https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352/1 "2022-01-14T03:03:40Z")

</div>

Hi, I am looking for best practice guidance when running the Elastic Agent and integrations in Docker containers. I have no issues getting them running (the documentation needs a bit of love as there are some inconsistencies around available environment variables etc), but I want to know what is the recommendation for persisting state, particularly with Fleet Server. Currently every time the container is destroyed and recreated an agent/fleet server registers. What paths within the container should I be looking to bind mount out to ensure state is persisted across container recreation / restart?

My current thought based on poking around the container is /usr/share/elastic-agent/state. From what I can tell this should give me the state information, as well as the logs. However I can see that when integrations are added, they are added under /usr/share/elastic-agent/data...

I have been unable to find any documentation regarding this. If the recommendation is NOT to persist state and treat them like a stateless agent, that is OK, but it is something that we will need to be aware of as every time we restart the agent we will end up with orphan agents listed in Fleet which will need to be cleaned up.

Thanks.

---

<div class="post-metadata">

**Author:** ![nemhods](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nemhods](https://discuss.elastic.co/u/nemhods)\
**Post date:** [January 14, 2022, 9:02pm UTC](https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352/2 "2022-01-14T21:02:47Z")

</div>

A while ago I asked this, and the answer was:

> For the persistence: Both ways should work. There is one issue we are currently working on for the fresh enrollment each time: The list of Elastic Agent in Fleet keeps getting longer and is not automatically cleaned up. The concept we have in mind to solve this is ephemeral agents which is agent which automatically are unenrolled after some time of inactivity.

> [@Fleet Server installation options](https://discuss.elastic.co/t/fleet-server-installation-options/274261/5):
>
> Thanks for sharing all the details also for others here! @blaker Could you take a look at the CA issues? For the persistence: Both ways should work. There is one issue we are currently working on for the fresh enrollment each time: The list of Elastic Agent in Fleet keeps getting longer and is not automatically cleaned up. The concept we have in mind to solve this is ephemeral agents which is agent which automatically are unenrolled after some time of inactivity.

Not sure if anything has changed since.

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [January 17, 2022, 8:49am UTC](https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352/3 "2022-01-17T08:49:50Z")

</div>

There is an `unenroll_timeout` which now can be set per policy: [Set enrollment timeout for ephemeral hosts | Fleet and Elastic Agent Guide [7.17] | Elastic](https://www.elastic.co/guide/en/fleet/7.17/set-enrollment-timeout.html) This should help in this scenario.

---

<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:** [February 14, 2022, 10:50am UTC](https://discuss.elastic.co/t/elastic-agent-state-persistence-in-docker/294352/4 "2022-02-14T10:50:24Z")

</div>

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