You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can mark environment variables as required using the `:?` syntax. Required variables must be set before deployment and will be highlighted in Coolify's UI with a red border if empty.
122
-
123
-
```yaml
124
-
services:
125
-
myapp:
126
-
environment:
127
-
# Required variables - deployment will fail if not set
128
-
- DATABASE_URL=${DATABASE_URL:?}
129
-
- API_KEY=${API_KEY:?}
130
-
131
-
# Required variables with default values - prefilled in UI but can be changed
132
-
- PORT=${PORT:?3000}
133
-
- LOG_LEVEL=${LOG_LEVEL:?info}
134
-
135
-
# Optional variables - standard behavior
136
-
- DEBUG=${DEBUG:-false}
137
-
- CACHE_TTL=${CACHE_TTL:-3600}
138
-
```
139
-
140
-
**Key behaviors:**
141
-
142
-
- **Required variables** (`${VAR:?}`) appear first in the environment variables list and show a red border when empty
143
-
- **Required with defaults** (`${VAR:?default}`) are prefilled with the default value but remain editable
144
-
- **Optional variables** (`${VAR:-default}`) use standard Docker Compose behavior
145
-
146
-
If a required variable is not set during deployment:
147
-
148
-
- Coolify will highlight the missing variable in the UI
149
-
- The deployment will be prevented until all required variables are provided
150
-
- Clear error messages guide users to fix the configuration
103
+
### Using Environment and Shared Variables
151
104
152
-
This validation happens before container creation, preventing partial deployments and runtime failures.
153
-
154
-
### Coolify's Magic Environment Variables
155
-
156
-
Coolify can generate dynamic environment variables for you using the following syntax: `SERVICE_<TYPE>_<IDENTIFIER>`.
157
-
158
-
::: warning HEADS UP!
159
-
Support for Magic Environment Variables in Compose files based on Git sources has been added in Coolify v4.0.0-beta.411
Within Coolify you can configure these easily following the details found in the [Knowledge Base for Docker Compose](/knowledge-base/compose#defining-environment-and-shared-variables).
237
106
238
107
### Storage
239
108
@@ -293,15 +162,15 @@ By default, each compose stack is deployed to a separate network named after you
293
162
294
163
If you want to connect services across different stacks (for example, linking an application to a separate database), enable the **Connect to Predefined Network** option on your Service Stack page.
Note that you must use the full name (like `postgres-<uuid>`) when referencing a service in another stack.
299
168
300
169
### Raw Docker Compose Deployment
301
170
302
171
For advanced users, Coolify offers a "Raw Compose Deployment" mode. This option lets you deploy your Docker Compose file directly without many of Coolify's additional configurations.
Coolify supports marking environment variables as required using Docker Compose's built-in syntax. This feature improves the deployment experience by validating critical configuration before starting services.
80
-
81
-
### Syntax
82
-
83
-
Use the `:?` syntax to mark variables as required:
80
+
You can mark environment variables as required using the `:?` syntax. Required variables must be set before deployment and will be highlighted in Coolify's UI with a red border if empty.
84
81
85
82
```yaml
86
83
services:
87
-
webapp:
84
+
myapp:
88
85
environment:
89
-
# Required variable - must be set, no default
86
+
# Required variables - deployment will fail if not set
90
87
- DATABASE_URL=${DATABASE_URL:?}
88
+
- API_KEY=${API_KEY:?}
91
89
92
-
# Required variable with default value - prefilled but editable
90
+
# Required variables with default values - prefilled in UI but can be changed
93
91
- PORT=${PORT:?3000}
92
+
- LOG_LEVEL=${LOG_LEVEL:?info}
94
93
95
-
# Optional variable with default - standard Docker Compose behavior
94
+
# Optional variables - standard behavior
96
95
- DEBUG=${DEBUG:-false}
96
+
- CACHE_TTL=${CACHE_TTL:-3600}
97
97
```
98
98
99
99
**Key behaviors:**
@@ -110,35 +110,71 @@ If a required variable is not set during deployment:
110
110
111
111
This validation happens before container creation, preventing partial deployments and runtime failures.
112
112
113
-
## Coolify's magic environment variables
113
+
### Shared Environment Variables
114
+
115
+
Coolify doesn't directly detect **shared** environment variables in the compose file, but are able to be referenced using with an additional step.
116
+
117
+
1. Create your shared variable following the [shared variables documentation](/knowledge-base/environment-variables#shared-variables).
118
+
119
+
2. Define your variables in your Docker Compose file, for example;
120
+
121
+
```yaml
122
+
services:
123
+
myservice:
124
+
environment:
125
+
- HARD_CODED=dev # Passed to the container, but not visible in Coolify's UI.
126
+
- SOME_OPTIONAL_VARIABLE=${SOME_VARIABLE_IN_COOLIFY_UI} # Creates an editable, uninitialized variable in the UI.
127
+
volumes:
128
+
- data-persist:/var/data
129
+
volumes:
130
+
data-persist:
131
+
device: /mnt/serverstorage/${SOME_VARIABLE_IN_COOLIFY_UI} # Re-uses the variable
132
+
```
133
+
134
+
3. Define the variable explicitly in the applications Environment Variables referencing your shared variable created in step 1;
Or in the normal view, the Name is what's referenced in the Docker Compose file `SOME_VARIABLE_IN_COOLIFY_UI` with the Value being the referenced environment variable `{{environment.SOME_SHARED_VARIABLE}}` as seen below. Once saved if correct, you'll see there's a third text box, if you reveal this, you should be able to see the true value, in this case `SOME_VALUE`.
Additionally, Coolify can generate some dynamic environment variables for you.
116
-
The syntax is `SERVICE_<TYPE>_<IDENTIFIER>`.
117
-
Type may be one of:
150
+
### Coolify's Magic Environment Variables
118
151
119
-
- **FQDN**: This will [generate](/knowledge-base/server/introduction#wildcard-domain) an FQDN for the service. The example below shows how you can add paths and ports.
120
-
- **URL**: Generates an URL based on the FQDN you have defined. Prefer this to generate URL for your services
152
+
Coolify can generate dynamic environment variables for you using the following syntax: `SERVICE_<TYPE>_<IDENTIFIER>`. The type may be one of:
153
+
154
+
- **URL**: This will [generate](/knowledge-base/server/introduction#wildcard-domain) an URL for the service. The example below shows how you can add paths and ports.
155
+
- **FQDN**: Generates FQDN for the service based on the URL you have defined. The example below shows how you can add paths and ports.
121
156
- **USER**: Generates a random string using `Str::random(16)`. You might want to use it as a username in your service.
122
157
- **PASSWORD**: Generates a password using `Str::password(symbols: false)`. Use `PASSWORD_64` to generate a 64 bit long password with `Str::password(length: 64, symbols: false)`.
123
158
- **BASE64**: Generates a random string using `Str::random(32)`. For longer strings, use `BASE64_64` or `BASE64_128`.
124
-
- **REALBASE64**: Encodes a randomly generated string using `base64_encode(Str::random(32))`. For longer strings, use `REALBASE64_64` or `REALBASE64_128`.
125
-
126
-
Every generated variable can be reused and will always have the same value for every service.
127
-
All generated variables are displayed in Coolify's UI for environment variables and can be edited there (except FQDN and URl).
128
159
129
-
::: info Naming
130
-
Names with underscores (`_`) cannot use ports in environment variables. Use hyphens (`-`) instead to avoid this limitation.
160
+
::: info Identifier Naming
161
+
Identifier with underscores (`_`) cannot use ports in environment variables. Use hyphens (`-`) instead to avoid this limitation.
131
162
132
163
```
133
164
SERVICE_URL_APPWRITE_SERVICE_3000 ❌
134
165
SERVICE_URL_APPWRITE-SERVICE_3000 ✅
135
166
```
167
+
136
168
:::
137
169
170
+
Every generated variable can be reused and will always have the same value for every service.
171
+
All generated variables are displayed in Coolify's UI for environment variables and can be edited there (except FQDN and URl).
172
+
138
173
As an example, imagine an application with UUID `vgsco4o` (generated by Coolify on creation).
139
174
It uses a compose file deploying Appwrite on the [wildcard](/knowledge-base/server/introduction#wildcard-domain) domain `http://example.com` .
Copy file name to clipboardExpand all lines: docs/knowledge-base/environment-variables.md
+2-13Lines changed: 2 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,20 +37,9 @@ You can set them on the `Projects` page, under the gear icon and use it with <co
37
37
38
38
You can set them on the `Environments` page (select a `Project`), under the gear icon and use it with <codev-pre>{{environment.NODE_ENV}}</code> Do not replace "environment" with your actual environment name.
39
39
40
-
####Using Shared Variables in Compose File
40
+
### Using Environment and Shared Variables in Docker Compose
41
41
42
-
If you want to use the environment variables in your compose file, you can do so by using the following syntax:
43
-
44
-
```bash
45
-
environment:
46
-
- NODE_ENV=${NODE_ENV}
47
-
```
48
-
49
-
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):
50
-
51
-
```bash
52
-
NODE_ENV={{team.NODE_ENV}}
53
-
```
42
+
Within Coolify you can configure these easily following the details found in the [Knowledge Base for Docker Compose](/knowledge-base/compose#defining-environment-and-shared-variables).
0 commit comments