Skip to content

Environment Variables

You can define environment variables for your resources, and they will be available in your application.

Preview Deployments could have different environment variables, so you can test your application as a staging environment for example.

Build Time Variables

If you would like to set environment variables for the build process, you can do it by setting the checkbox Build Variable in the normal view on the UI.

Shared Variables

You could have 3 types of shared variables:

  1. Team Based
  2. Project Based
  3. Environment Based (production, staging, etc.)

You can set shared variables on their respective pages.

Then you can use these variables anywhere. For example: You defined NODE_ENV to production.

Team Based

You can set them on the Team page and use it with {{team.NODE_ENV}}. Do not replace “team” with your actual team name.

Project Based

You can set them on the Projects page, under the gear icon and use it with {{project.NODE_ENV}}. Do not replace “project” with your actual project name.

Environment Based

You can set them on the Environments page (select a Project), under the gear icon and use it with {{environment.NODE_ENV}}. Do not replace “environment” with your actual environment name.

Using Shared Variables in Compose File

If you want to use the environment variables in your compose file, you can do so by using the following syntax:

environment:
- NODE_ENV=${NODE_ENV}

And then in the UI set NODE_ENV to your desired shared variable. For example if you want to use a team based variable (make sure you have the NODE_ENV variable set in the Team Variables):

NODE_ENV=${team.NODE_ENV}

Predefined Variables

Coolify predefines some variables for you, so you can use them in your application. All you need to do is to add an environment variable like this to your application.

Terminal window
# For example, you can use this variable in your application
MY_VARIABLE=$SOURCE_COMMIT
# You will have the commit hash of the source code in your application as an environment variable in MY_VARIABLE

COOLIFY_FQDN

Fully qualified domain name(s) of the application.

COOLIFY_URL

URL(s) of the application.

COOLIFY_BRANCH

Branch name of the source code.

COOLIFY_CONTAINER_NAME

Name of the container generated by Coolify.

SOURCE_COMMIT

Commit hash of the source code.

PORT

If not set: it is set to the Port Exposes’s first port.

HOST

If not set: it is set to 0.0.0.0.