> For the complete documentation index, see [llms.txt](https://django-cloud.gitbook.io/django-cloud-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://django-cloud.gitbook.io/django-cloud-docs/how-it-works/ephemeral-container.md).

# Persistent files and the ephemeral container

Your app runs in a container, and **the container's filesystem is ephemeral**. Anything your app writes to disk is lost when the container restarts, when you deploy a new release, when you scale, and when AWS moves your app to another node.

{% hint style="danger" %}
Never keep data you care about on the container's disk. That includes uploaded files, a SQLite database, generated reports and anything cached on disk that you can't recreate.
{% endhint %}

## What this means for a Django app

| What                              | Do this instead                                                                                                             |
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **Database**                      | Use a managed Postgres database. SQLite files are lost on every deploy.                                                     |
| **User uploads** (`MEDIA_ROOT`)   | Store them in object storage such as Amazon S3, for example with `django-storages`.                                         |
| **Static files**                  | `collectstatic` runs during the build, so they are baked into the image. Serve them with WhiteNoise or from object storage. |
| **Sessions and cache**            | Use the database, or an external cache. Don't rely on files or in-process memory, especially with more than one instance.   |
| **Scheduled and background work** | Run it as a separate service. A process inside the web container stops whenever the container does.                         |

## More than one instance

If you scale to several instances, each has its own filesystem and its own memory. Anything that must be shared, such as sessions, caches and files, has to live outside the container.

## Temporary files are fine

Use the disk freely for temporary work within a single request, for example resizing an image before sending it to S3. Just don't expect it to be there later.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://django-cloud.gitbook.io/django-cloud-docs/how-it-works/ephemeral-container.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
