Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
Use multiple environment variables in docker compose path

I have the following compose file:

services:
  myproject:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_HTTPS_PORT=44308
      - PROJECT_NAME=MyProject
    volumes:
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/Turma/${PROJECT_NAME}/Logs:/var/logs/${PROJECT_NAME}

On the line:

      - ${APPDATA}/Turma/${PROJECT_NAME}/Logs:/var/logs/${PROJECT_NAME}

It recognises ${APPDATA} but for ${PROJECT_NAME} it uses the literal string not the environment variable value.

Is there a way to make this work so the actual project name is used in path?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As far as I am aware, you cannot reference your env variables defined within the compose file later in the same compose file and have them interpreted. Your definition of $APPDATA works since that's set in the host's environment, not the compose file.

I tested both using the env variable and a .env file with compose 2.3 and 3, and neither worked.

I recommend wrapping your compose file in a run script where you can set the variables needed in your host shell, so you can have those interpreted properly. If you're deploying with a standard tool such as ansible, jenkins, etc. those can all set variables for you. This can look like the following:

#!/bin/bash
export PROJECT_NAME=foo
docker-compose up -d
unset PROJECT_NAME

Although it may not work for creating volumes, if you just need the variable to do something during the container's runtime (such as setting another environment variable), that can be put into an entrypoint script as well.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!