0

I have to set a environment variable to the absolute path of the docker-compose.yml file. I tried ${PWD} (see below). However, as expected, PWD is the path from where the docker compose command is executed and not the path of the docker-compose.yml file.

How can I do this?

In case this is not possible, is there a way to configure docker compose that it always changes the PWD to the location of the docker-compose.yml file?

services:
    environment:
      TEST_ENV: ${PWD}/data
3
  • That environment variable will be used in the container, which won't have access to the host filesystem; using the host path of the Compose file won't be that meaningful to the container code. Can you use a fixed container path here instead?
    – David Maze
    Commented Sep 4 at 23:47
  • This environment variable is used by the container to create volumes (bind) on new container it spawns.
    – Meinrad
    Commented Sep 5 at 0:08
  • you can either use environment file and set the path manually, use a script to dynamically set the path, use Docker Compose Override Files or lastly use Docker Compose variable substitution with .env . apart from these i dont think there are any option , plase check the above and try to meet your requirements.
    – 0xn0b174
    Commented Sep 5 at 1:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.