[英]Docker Django Postgres FATAL: password authentication failed for user "postgres
I am dockerizing my Django app.我正在对接我的 Django 应用程序。 My configs are the following:
我的配置如下:
csgo.env csgo.env
POSTGRES_NAME='postgres'
POSTGRES_USER='postgres'
POSTGRES_PASSWORD='postgres'
POSTGRES_HOST='postgres_db'
POSTGRES_PORT='5432'
settings.py设置.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('POSTGRES_NAME', 'postgres'),
'USER': os.getenv('POSTGRES_USER', 'postgres'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.getenv('POSTGRES_HOST', 'postgres_db'),
'PORT': os.getenv('POSTGRES_PORT', '5432'),
}
}
docker-compose.yml docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
env_file:
- csgo.env
ports:
- '8000:8000'
volumes:
- .:/code
depends_on:
- postgres_db
postgres_db:
image: postgres:13
restart: always
ports:
- '5432:5432'
env_file:
- csgo.env
environment:
- POSTGRES_NAME='postgres'
- POSTGRES_USER='postgres'
- POSTGRES_PASSWORD='postgres'
- POSTGRES_HOST='postgres_db'
- POSTGRES_PORT='5432'
When I run docker-compose up
, I get the typical auth error django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"
and I am really stressed of it.当我运行
docker-compose up
,我得到典型的身份验证错误django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"
我真的很紧张。 I have been looking for a typo a day long and haven't figured it out.我一直在寻找一个错字,但一直没有弄清楚。 Please help me to find the missing piece of code or the typo!
请帮我找到丢失的代码或错字!
Note: I know that this kind of questions are overflowed on the Internet.注意:我知道这种问题在网上泛滥成灾。 My post is about finding a typo or a mechanical mistake by me.
我的帖子是关于发现我的错字或机械错误。 Thanks for understanding and not assigning the post as a duplicate one!
感谢您的理解,不要将帖子分配为重复的!
you should set database name in your environment variables:您应该在环境变量中设置数据库名称:
POSTGRES_DB='postgres'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.