---
title: "Environment variables"
description: "Set runtime and build-time environment variables in OnePloy, reuse them with shared variables and use generated values in Compose files."
url: https://oneploy.dev/docs/applications/environment-variables/
type: op_doc
published: 2026-11-02T19:09:47+00:00
updated: 2026-11-02T19:11:22+00:00
author: "admin"
language: en-US
---

# Environment variables

> Set runtime and build-time environment variables in OnePloy, reuse them with shared variables and use generated values in Compose files.

Environment variables pass configuration and secrets to your application. Add them on the application’s **Environment variables** page, choose whether each one is available at build time, at runtime or both, and redeploy to apply changes.

## How do I add a variable?

1. Open the application and go to **Environment variables**.
2. Add a key and value, or switch to the bulk editor and paste several `KEY=value` lines.
3. Save, then redeploy the application.

```dotenv
DATABASE_URL=postgres://app:secret@my-postgres:5432/app
APP_ENV=production
```

## What options does each variable have?

| Option | Effect |
| --- | --- |
| Build time | Available while the image is built. |
| Runtime | Available inside the running container. |
| Interpolation | When set to literal, a `$NAME` inside the value is kept as plain text instead of being expanded. |
| Value type | Lets a value span several lines, for example a certificate or private key. |
| Comment | A note documenting what the variable is for. |

Variables are kept in two sets: **Production** and **Preview deployments**. The preview set applies only to [preview deployments](https://oneploy.dev/docs/applications/preview-deployments/), so you can point pull request builds at a staging database.

## How do I keep build secrets out of the image?

Enable **Build secrets** to pass build-time variables as Docker BuildKit secrets. The values are available during the build but are not written into the final image layers.

## How do I share a value between resources?

Use **Shared Variables** in the sidebar. Define a variable once at one of four levels, then reference it from any resource in that scope:

| Level | Reference syntax |
| --- | --- |
| Team | `{{team.NAME}}` |
| Project | `{{project.NAME}}` |
| Environment | `{{environment.NAME}}` |
| Server | `{{server.NAME}}` |

The reference must be the whole value of the variable:

```dotenv
STRIPE_KEY={{team.STRIPE_KEY}}
```

When the shared value changes, redeploy the resources that use it.

## Which variables does OnePloy set automatically?

- `PORT` is set from the exposed port if you did not define it yourself.
- `HOST` is set to `0.0.0.0` if you did not define it, so the app listens on all interfaces.
- `SOURCE_COMMIT` holds the deployed Git commit when source commit availability is enabled in the advanced settings.

## Generated values in Docker Compose

Compose-based applications and services can ask OnePloy to generate values. Any variable that starts with one of these prefixes is filled in when the resource is created, and kept stable afterwards:

| Prefix | Generated value |
| --- | --- |
| `SERVICE_URL_<NAME>` | The full URL assigned to that service. Add a port suffix, such as `SERVICE_URL_APP_3000`, to route the URL to that container port. |
| `SERVICE_FQDN_<NAME>` | The hostname assigned to that service. |
| `SERVICE_USER_<NAME>` | A random username. |
| `SERVICE_PASSWORD_<NAME>` | A random password. `SERVICE_PASSWORD_64_<NAME>` produces a longer one. |
| `SERVICE_BASE64_<NAME>` | A random base64 string, for example for app secrets. |

See [Custom Docker Compose](https://oneploy.dev/docs/services/custom-docker-compose/) for an example.

## Can I manage variables through the API?

Yes. Applications, databases and services each have `envs` endpoints, including a bulk update, for example `PATCH /api/v1/applications/{uuid}/envs/bulk`. Shared variables have team, project, environment and server endpoints such as `GET /api/v1/team/envs`. See the [API overview](https://oneploy.dev/docs/api/).

**Warning:** Anyone with access to the resource settings can read its variables. Restrict who can view secrets with [team roles](https://oneploy.dev/docs/teams/), and give API tokens the `read:sensitive` permission only when needed.

---

Source: https://oneploy.dev/docs/applications/environment-variables/ · OnePloy
