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?
- Open the application and go to Environment variables.
- Add a key and value, or switch to the bulk editor and paste several
KEY=valuelines. - Save, then redeploy the application.
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, 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:
STRIPE_KEY={{team.STRIPE_KEY}}
When the shared value changes, redeploy the resources that use it.
Which variables does OnePloy set automatically?
PORTis set from the exposed port if you did not define it yourself.HOSTis set to0.0.0.0if you did not define it, so the app listens on all interfaces.SOURCE_COMMITholds 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 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.
Warning: Anyone with access to the resource settings can read its variables. Restrict who can view secrets with team roles, and give API tokens the read:sensitive permission only when needed.