'Is it possible to reference an .env variable inside another .env variable

I have this little .env file for a docker-compose.yaml:

POSTGRES_USER="root"
POSTGRES_PASSWORD="s3cr3t_p4ssw0rd"
POSTGRES_DB="test"
POSTGRESQL_URL="postgresql://root:s3cr3t_p4ssw0rd@localhost:5432/test?schema=public"

I would like to reference the POSTGRES_ variables inside POSTGRESQL_URL.

From what I know, this is not possible, because the .env file is only a text file with key-value pairs.

Is it now possible? Or can Docker understand it?

This is a question about docker, but I would like to know if it is possible in bash or other environments



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source