I have multiple Environment Variables defined on my Postgres container, such as POSTGRES_USER. The container is running and I want to connect to Postgres from the command line using exec.
I'm unable to connect with the following:
docker exec -it <CONTAINER-ID> psql -U $POSTGRES_USER -d <DB NAME>
I understand that the variable is defined on the container and the following does work:
docker exec -it <CONTAINER-ID> bash -c 'psql -U $POSTGRES_USER -d <DB NAME>'
Is there a way for me to execute the psql command directly from docker exec and call the environment variable on the container?
docker exec -it <CONTAINER-ID> psql -U ????? -d <DB NAME>
'$POSTGRES_USER'psql: error: could not connect to server: FATAL: role "$POSTGRES_USER" does not existsh -c 'psql -U $POSTGRES_USER <dbname>'. I think it is necessary to pass it toshfor the environment variable to be evaluated. If I find another way I will comment here.