Environment variables and build args for Docker Compose in Coolify

Published: 2024-08-20 | Updated: 2026-09-14

It is recommended to create a .env.example file to your project with all your environment variables.

If you want to pre-populate environment variables to show up in Coolify UI, you can do so by defining them in docker-compose.yaml with the following syntax:

services:
  myservice:
    environment:
      # Gets passed to the container but will not be visible in Coolify's UI
      - SOME_HARDCODED_VALUE=hello
      # Creates an uninitialized environment variable editable in Coolify's UI
      - SOME_VARIABLE=${SOME_VARIABLE}
      # Creates an environment variable of value "hello" editable in Coolify's UI
      - SOME_DEFAULT_VARIABLE=${SOME_DEFAULT_VARIABLE:-hello}

See Coolify Docs on defining environment variables for more info.

Setting variables in Coolify UI

  1. Navigate to Environment Variables configuration in your project
  2. Set Build secrets to “Docker BuildKit secrets” if you use build secrets
  3. Open Developer view
  4. Copy contents of .env.example file to Production section
  5. Set environment variables
  6. Switch back to Normal view
  7. Lock any sensitive variables such as secrets and passwords

[!WARNING]

Do NOT set Interpolation to “Literal” as it silently adds ' characters to the variables. You should avoid using special characters in values and stick to alphanumeric if possible because Coolify has a habit of messing up values with special characters.

How to use build args with Docker Compose

Set Build -> Build arguments to Managed manually in Dockerfile in advanced settings. ARGs should always be manually defined in Dockerfile. Then just add them to docker-compose.yaml.

# docker-compose.yml
services:
  app:
    build:
      dockerfile: Dockerfile
      args:
        MY_BUILD_ARG: ${MY_BUILD_ARG}

All content © Kimmo Salmela — Source on GitHub