-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow using variables from docker-compose.env in volume paths (and other configs in docker-compose.yml) #2636
Comments
As I mentioned in #2352, there is precedent for this already with existing tools reading from a So long as |
Indeed seems like #2352 is requesting the exact same thing (my bad for not spotting it and opening a dupe) |
For me it would be much more preferable to have the environment read from the shell by default instead of a file. I can always source a file before running a command. The proposal in #2441 seems like a much better solution as it uses a familiar shell syntax for providing default values in variable expansion and doesn't create the loop problem the op mentions. |
Unless I'm mistaken, this issues seems to still not be resolved specifically because environment variables can't be used in volume keys (#3998). I'm running into this problem now. |
Ah, thanks. I missed that the proposal in #3998 (comment) was merged in. The reply after it made it sound like it was rejected. |
To just change the ending name like this, if it could be a solution to your issue... version: "3.4"
services:
database:
volumes:
- "fix-name-volume:/var/lib/postgresql/data"
volumes:
fix-name-volume:
name: ${REAL_NAME_OF_VOLUME} # Real ending name
external: false
|
In my case, Using volume name way didn't work. but put the envvar into volume name directly, it works.
Docker version 18.03.1-ce, build 9ee9f40 |
@tsu1980 Where is |
It works if version: '3.7'
services:
testlet:
image: alpine:latest
volumes:
- ${MY_DIR}:/mounted
command: ["cat", "/mounted/foo.txt"] So if I had the |
You can actually achieve the same using anchors instead of ENVs. Here's a simple example: version: "3.6"
x-source-path: &source-path /home/external-user
x-target-path: &target-path /home/internal-user
services:
volumes-mapping:
image: ubuntu
tty: true
volumes:
- type: bind
source: *source-path
target: *target-path
environment:
SOURCE_PATH_ENV: *source-path
TARGET_PATH_ENV: *target-path
|
I know that it is already possible to use shell environment variables which will expand in the definition of e.g. the path of a mount volume
But to set all the environment variables I need, this forces me to write some shell wrappers around the invocation of docker-compose (a one liner, admittedly, but I am a lazy bum...)
Since I already use a docker-compose.env file to define variables which are used in the construction of the containers, I wonder:
would it make sense to expand the variables in the docker-compose.env file so that they are available in docker-compose.yml ? (apart from an obvious loop problem of using them to define the value for 'env_file'...)
The text was updated successfully, but these errors were encountered: