Use a value of an environment variable as name of another environment variable on docker compose yaml?

I want use the value of an environment variable to retrieve another environment variable, let me explicate with an example:

I created a list of variable into .env file like this:

DONALD=666
JOE=135
BARACK=130
GEORGE=830
BILL=268

and on yaml file I want retrive the value stored into one of the previous variable using the host environment variable ‘USER’; now, $USER works fine, I’m able to have the name of user that is using the docker-compose file but I’m not able to use this value as name of a variable to retrieve the mapped numeric value stored into the variables.
Is it possible do it?

Hello,
It’s a bit of a bummer, but its engine is just too “dumb” to handle nested variables like ${${USER}}. It sees the first and stops looking for more logic. To get around it, you have to do the “logic” in your terminal before you hit the command.

This maps USER (e.g., DONALD) to its value (666)

export MAPPED_VALUE=${!USER}

Then just use ${MAPPED_VALUE} in your yaml

docker-compose up -d

It’s a bit of an extra step, but it’s the cleanest way to bridge that gap.

Yes, I saw…
I resolved creating a variable into host with a different value for each user, but with the same name. It works.