1

In docker compose, is there any possibility to use env variable to instead direct values.

volumes: - /opt:$$VARIABLE

ERROR: compose.cli.main.main: The Compose file './docker-compose.yml' is invalid because:

please let me know is there any way to do this.

1 Answer 1

1

Docker compose support environment variables out of the box but volumes must have an absolute path.

Export variable -

$ export VARIABLE=vijay

Change in compose -

volumes:
  - /opt:/home/${VARIABLE}
Sign up to request clarification or add additional context in comments.

2 Comments

it is not working, however i am using env file to do inject variables to access. It seems to be volumes is expecting absolute path to specify.!
Yes, variables will expand but you need to specify absolute path, have updated the answer.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.