I'm trying to set env_file to a file with several environment variables for my postgreSQL connection string but when I run docker-compose build, I get this error:
time="2023-10-16T16:43:46-04:00" level=warning msg="The \"PGUSER\" variable is not set. Defaulting to a blank string."
time="2023-10-16T16:43:46-04:00" level=warning msg="The \"PGPASSWORD\" variable is not set. Defaulting to a blank string."
time="2023-10-16T16:43:46-04:00" level=warning msg="The \"PGDATABASE\" variable is not set. Defaulting to a blank string."
time="2023-10-16T16:43:46-04:00" level=warning msg="The \"PGPORT\" variable is not set. Defaulting to a blank string."
time="2023-10-16T16:43:46-04:00" level=warning msg="The \"PGPORT\" variable is not set. Defaulting to a blank string."
1 error(s) decoding:
* error decoding 'ports': No port specified: :<empty>
Here is my docker-compose:
version: "3.11"
services:
app:
container_name: app_container
build: .
volumes:
- .:/django
ports:
- 8000:8000
image: app:django
command: python manage.py runserver 0.0.0.0:8000
depends_on:
- db
db:
container_name: postgres_container
env_file:
- .env.prod
image: postgres
restart: always
environment:
POSTGRES_USER: ${PGUSER}
POSTGRES_PASSWORD: ${PGPASSWORD}
POSTGRES_DB: ${PGDATABASE}
ports:
- "${PGPORT}:${PGPORT}"
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: Password12345
ports:
- "5050:80"
Here is my env_file:
PGHOST="127.0.0.1"
PGUSER="postgres"
PGPORT=5432
PGDATABASE="dev_db"
PGPASSWORD="postgres"
As you can see, they are in the same directory.

The solution is to use single quote instead of double quote in .env file..
### USE THIS
HONEYPOT_SECRET='bUTtBM$mw*3ZoDr7t#aa12F$SM%0'
### INSTEAD OF THIS
HONEYPOT_SECRET="bUTtBM$mw*3ZoDr7t#aa12F$SM%0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With