-
-
Notifications
You must be signed in to change notification settings - Fork 209
Update and consolidate Docker Compose variable documentation. #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1b3c871
41faa7b
1a4c691
dc93f58
dff667a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -108,13 +108,74 @@ Coolify automatically detects environment variables mentioned in your compose fi | |||||
| services: | ||||||
| myservice: | ||||||
| environment: | ||||||
| - SOME_HARDCODED_VALUE=hello # Passed to the container, but not visible in Coolify's UI. | ||||||
| - SOME_VARIABLE=${SOME_VARIABLE_IN_COOLIFY_UI} # Creates an editable, uninitialized variable in the UI. | ||||||
| - SOME_DEFAULT_VARIABLE=${OTHER_NAME_IN_COOLIFY:-hello} # Sets a default value "hello" that can be edited. | ||||||
| - SOME_HARDCODED_VALUE=hello # Gets passed to the container but will not be visible in Coolify's UI | ||||||
| - SOME_VARIABLE=${SOME_VARIABLE_IN_COOLIFY_UI} # Creates an uninitialized environment variable editable in Coolify's UI | ||||||
| - SOME_DEFAULT_VARIABLE=${OTHER_NAME_IN_COOLIFY:-hello} # Creates an environment variable of value "hello" editable in Coolify's UI | ||||||
| ``` | ||||||
|
|
||||||
| <ZoomableImage src="/docs/images/builds/packs/compose/6.webp" /> | ||||||
|
|
||||||
| #### Shared Environment Variables | ||||||
|
|
||||||
| Coolify doesn't directly detect **shared** environment variables in the compose file, but are able to be referenced using with an additional step. | ||||||
|
|
||||||
| 1. Create your shared variable following the [shared variables documentation](/knowledge-base/environment-variables#shared-variables). | ||||||
|
|
||||||
| 2. Define your variables in your Docker Compose file, for example; | ||||||
|
|
||||||
| ```yaml | ||||||
| services: | ||||||
| myservice: | ||||||
| environment: | ||||||
| - HARD_CODED=dev # Passed to the container, but not visible in Coolify's UI. | ||||||
| - SOME_OPTIONAL_VARIABLE=${EnvironmentNameShort} # Creates an editable, uninitialized variable in the UI. | ||||||
| volumes: | ||||||
| - data-persist:/var/data | ||||||
| volumes: | ||||||
| data-persist: | ||||||
| device: /mnt/serverstorage/${EnvironmentNameShort} # Re-uses the variable | ||||||
| ``` | ||||||
|
|
||||||
| 3. Define the variable explicitly in the applications Environment Variables referencing your shared variable created in step 1; | ||||||
|
|
||||||
| If in developer view, you can enter it like so; | ||||||
| ``` | ||||||
| EnvironmentNameShort={{environment.EnvironmentNameShort}} | ||||||
|
||||||
| EnvironmentNameShort={{environment.EnvironmentNameShort}} | |
| SOME_VARIABLE_IN_COOLIFY_UI={{environment.SOME_SHARED_VARIABLE}} |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as already mentioned above.
| Or in the normal view, the Name is what's referenced in the Docker Compose file `EnvironmentNameShort` with the Value being the referenced environment variable `{{environment.EnvironmentNameShort}}` 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. | |
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,40 +61,7 @@ For further details, please refer to the [Docker Networking in Compose](https:// | |
|
|
||
| ## Defining environment variables | ||
|
|
||
| Coolify will notice the environment variables you mention in your compose file and will display it in its UI. | ||
|
|
||
| ```yaml | ||
| services: | ||
| myservice: | ||
| environment: | ||
| - SOME_HARDCODED_VALUE=hello # Gets passed to the container but will not be visible in Coolify's UI | ||
| - SOME_VARIABLE=${SOME_VARIABLE_IN_COOLIFY_UI} # Creates an uninitialized environment variable editable in Coolify's UI | ||
| - SOME_DEFAULT_VARIABLE=${OTHER_NAME_IN_COOLIFY:-hello} # Creates an environment variable of value "hello" editable in Coolify's UI | ||
| ``` | ||
|
|
||
| <ZoomableImage src="/docs/images/screenshots/Docker-compose-environment-variables-UI.webp" /> | ||
|
|
||
| ## Required environment variables | ||
|
|
||
| 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. | ||
|
|
||
| ### Syntax | ||
|
|
||
| Use the `:?` syntax to mark variables as required: | ||
|
|
||
| ```yaml | ||
| services: | ||
| webapp: | ||
| environment: | ||
| # Required variable - must be set, no default | ||
| - DATABASE_URL=${DATABASE_URL:?} | ||
|
|
||
| # Required variable with default value - prefilled but editable | ||
| - PORT=${PORT:?3000} | ||
|
|
||
| # Optional variable with default - standard Docker Compose behavior | ||
| - DEBUG=${DEBUG:-false} | ||
| ``` | ||
| Please refer to [Defining Environment Variables in Docker Compose](/builds/packs/docker-compose#defining-environment-variables) | ||
|
|
||
| **Key behaviors:** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this + the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check it out, I haven't personally used any of the magic variables in my docker compose, but I suspect you'll be correct.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are actually Docker Compose specific, so I would say we add them in the Environment Variables page under Docker Compose. |
||
|
|
||
|
|
||
| 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 | |
|
|
||
| You can set them on the `Environments` page (select a `Project`), under the gear icon and use it with <code v-pre>{{environment.NODE_ENV}}</code> Do not replace "environment" with your actual environment name. | ||
|
|
||
| #### Using Shared Variables in Compose File | ||
| #### Using Shared Variables in a Docker Compose File | ||
|
|
||
| If you want to use the environment variables in your compose file, you can do so by using the following syntax: | ||
|
|
||
| ```bash | ||
| 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): | ||
|
|
||
| ```bash | ||
| NODE_ENV={{team.NODE_ENV}} | ||
| ``` | ||
| Please refer to [Shared Environment Variables in Docker Compose](/builds/packs/docker-compose#shared-environment-variables) | ||
|
||
|
|
||
| ## Predefined Variables | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recommend defining environment variables using upper snake case, we should keep that consinstent through out the docs. Maybe also give it a more generic name, which aligns better with the other examples.