> ## Documentation Index
> Fetch the complete documentation index at: https://www.aptible.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Containers

Aptible deploys all resources in Containers.

# Container Command

Containers run the command specified by the [Service](/core-concepts/apps/deploying-apps/services) they belong to:

* If the service is an [Implicit Service](/how-to-guides/app-guides/define-services#implicit-service-cmd), then that command is the [Image](/core-concepts/apps/deploying-apps/image/overview)'s `CMD`.
* If the service is an [Explicit Service](/how-to-guides/app-guides/define-services#explicit-services-procfiles), then that command is defined by the [Procfile](/how-to-guides/app-guides/define-services).

# Container Environment

Containers run with three types of environment variables and if there is a name collision, [Aptible Metadata](/reference/aptible-metadata-variables) takes precedence over App Configuration, which takes precedence over Docker Image Variables:

## Docker Image Variables

Docker [Images](/core-concepts/apps/deploying-apps/image/overview) define these variables via the `ENV` directive. They are present when your Containers start:

```dockerfile theme={null}
ENV FOO=BAR
```

## App Configuration

Aptible injects an App's [Configuration](/core-concepts/apps/deploying-apps/configuration) as environment variables. For example, for the keys `FOO` and `BAR`:

```shell theme={null}
aptible config:set --app "$APP_HANDLE" \
  FOO=SOME BAR=OTHER
```

Aptible runs containers with the environment variables `FOO` and `BAR` set respectively to `SOME` and `OTHER`.

## Aptible Metadata

Finally, Aptible injects a set of [metadata keys](/reference/aptible-metadata-variables) as environment variables.

These environment variables are accessible through the facilities exposed by the language, such as `ENV` in Ruby, `process.env` in Node, or `os.environ` in Python.

# Container Hostname

Aptible (and Docker in general) sets the hostname for your Containers to the 12 first characters of the Container's ID and uses it in [Logging](/core-concepts/observability/logs/overview) and [Metrics](/core-concepts/observability/metrics/overview).

# Container Isolation

Containers on Aptible are isolated. Use one of the following options to allow multiple Containers to communicate:

* For web APIs or microservices, set up an [Endpoint](/core-concepts/apps/connecting-to-apps/app-endpoints/overview) and direct your requests to the Endpoint.
* For background workers, use a [Database](/core-concepts/managed-databases/overview) as a message queue. Aptible supports [Redis](/core-concepts/managed-databases/supported-databases/redis) and [RabbitMQ](/core-concepts/managed-databases/supported-databases/rabbitmq), which are well-suited for this use case.

# Container Lifecycle

Containers on Aptible are frequently recycled during Operations - meaning new Containers are created during an Operation, and the old ones are terminated. This happens within the following Operations:

* Redeploying an App
* Restarting an App or Database
* Scaling an App or Database

### Graceful termination

Containers are given a grace period after the initial `SIGTERM` to exit before receiving a hard `SIGKILL`. By default this is 10 seconds, but it can be configured via the **stop timeout** setting on the service. See the [Releases](/core-concepts/apps/deploying-apps/releases/overview) page for more information and caveats.

# Filesystem Implications

With the notable exception of [Database](/core-concepts/managed-databases/overview) data, the filesystem for your [Containers](/core-concepts/architecture/containers/overview) is ephemeral. As a result, any data stored on the filesystem will be gone every time containers are recycled.

Never use the filesystem to retain long-term data. Instead, store this data in a Database or a third-party storage solution, such as AWS S3 (see [How do I accept file uploads when using Aptible?](/how-to-guides/app-guides/use-s3-to-accept-file-uploads) for more information).

<DocsTableOfContents />
