Skip to content

Conversation

bozau
Copy link

@bozau bozau commented Oct 1, 2025

Hi,

I've consolidated variable substitution documentation for Docker Compose into a single location as recommended by @ShadowArcanist, previously there were three separate locations, these were;

https://coolify.io/docs/knowledge-base/environment-variables#shared-variables
https://coolify.io/docs/knowledge-base/docker/compose#defining-environment-variables
https://coolify.io/docs/builds/packs/docker-compose#defining-environment-variables

I also added additional information regarding shared variables and how to configure and consume them better.

I hope that this will better help people on-boarding with Docker Compose.

Cheers.

Aaron.

…tional image and examples to better help visualize how to perform it
@github-actions github-actions bot changed the base branch from v4.x to next October 1, 2025 02:43
Copy link

github-actions bot commented Oct 1, 2025

Hi @bozau,

The base branch of this PR has been automatically changed to next.
All contributors must commit changes to the next branch.

A maintainer will review your PR within 5 to 7 business days. Thank you!

@ShadowArcanist ShadowArcanist requested a review from Cinzya October 1, 2025 06:45
@ShadowArcanist ShadowArcanist added ✨ Enhancement Suggestions to improve or add detail to existing docs. ⚖️ Medium Priority Important tasks to be addressed soon, but not urgent. labels Oct 1, 2025
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.
Copy link
Member

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.

Suggested change
- SOME_OPTIONAL_VARIABLE=${EnvironmentNameShort} # Creates an editable, uninitialized variable in the UI.
- SOME_OPTIONAL_VARIABLE=${SOME_VARIABLE_IN_COOLIFY_UI} # Creates an editable, uninitialized variable in the UI.


If in developer view, you can enter it like so;
```
EnvironmentNameShort={{environment.EnvironmentNameShort}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be a bit confusing for people. Thinking that the application env and the shared env need to share the same name, which afaik is not the case. Maybe we can re-name them, to mak the difference clear what is what.

Suggested change
EnvironmentNameShort={{environment.EnvironmentNameShort}}
SOME_VARIABLE_IN_COOLIFY_UI={{environment.SOME_SHARED_VARIABLE}}

EnvironmentNameShort={{environment.EnvironmentNameShort}}
```
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as already mentioned above.

Suggested change
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.

```bash
NODE_ENV={{team.NODE_ENV}}
```
Please refer to [Shared Environment Variables in Docker Compose](/builds/packs/docker-compose#shared-environment-variables)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would actually be better, to move everything in here, instead of /builds/packs/docker-compose#shared-environment-variables. Makes semantically more sense to have everything environment variables related under the environment variables page.
The Build Pack Docker Compose page is already long enough by itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure can do if that's the preferred location :)

```
Please refer to [Defining Environment Variables in Docker Compose](/builds/packs/docker-compose#defining-environment-variables)

**Key behaviors:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this + the magic environment section be moved as well then? They work the same across both as well.

Copy link
Author

@bozau bozau Oct 1, 2025

Choose a reason for hiding this comment

The 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.
From what I understand, the magic variables are across all of Coolify, and not docker compose specific right? If so, they probably should sit in the Environment Variables page, yeah?

Copy link
Member

Choose a reason for hiding this comment

The 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.
Appreciate the work btw! 😊

bozau added 2 commits October 3, 2025 10:11
…ced references where duplication was previously and moved the magic variables to the kb file for completeness
@bozau
Copy link
Author

bozau commented Oct 3, 2025

Hi @Cinzya and @ShadowArcanist ,

I believe that I've completed the changes including the suggestions, could you double check I've not missed something :)

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Enhancement Suggestions to improve or add detail to existing docs. ⚖️ Medium Priority Important tasks to be addressed soon, but not urgent.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants