I have the following .env file:
MY_SECRET_POSTGRES_PASSWORD=hello
I installed dotenv to load variables from this env file and run the docker command as follows:
dotenv -- docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=$MY_SECRET_POSTGRES_PASSWORD -d postgres
When I run the command, I get the following error:
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
However, when I just run the following command to ensure that the env is loaded, it shows up fine:
dotenv -- bash -c 'echo "$MY_SECRET_POSTGRES_PASSWORD"'
I know I can use --env-file to pass in the entire env file but I rather like to pick the values that I pass is so that I do not expose anything unnecessary to the container.