我正在运行一个Docker容器,该容器从另一台主机获取一个Postgres数据库。
看来我的docker compose文件正在连接到数据库 但是当我运行
docker exec -it container python manage.py makemigrations
要么
docker exec -it container python manage.py createsuperuser
我得到
2019-09-05 23:25:33.553 UTC [29] FATAL: password authentication failed for user "postgres_user"
db_1 | 2019-09-05 23:25:33.553 UTC [29] DETAIL: Role "postgres_user" does not exist.
db_1 | Connection matched pg_hba.conf line 95: "host all all all md5"
db_1 | 2019-09-05 23:26:27.289 UTC [30] FATAL: password authentication failed for user "postgres_user"
db_1 | 2019-09-05 23:26:27.289 UTC [30] DETAIL: Role "postgres_user" does not exist.
db_1 | Connection matched pg_hba.conf line 95: "host all all all md5"
这是我的docker compose文件的db部分
db:
image: postgres
environment:
- POSTGRES_HOST=host_ip
- POSTGRES_USER=postgres_user
- POSTGRES_PASSWORD=bad_password
- POSTGRES_DB=postgres_database
- POSTGRES_PORT=5432
ports:
- "5434:5432"
volumes:
- postgresql-data:/var/lib/postgresql/data
restart: always
这是我的settings.py中的数据库设置
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres_database',
'USER': 'postgres_user',
'PASSWORD':'bad_password',
'HOST': 'db',
'PORT': '5432',
}
}
运行psql host_db_ip -U postgres_user -W
可以正常工作,并且可以连接。我尝试删除所有docker映像,容器和系统,并重建所有内容。我的猜测是docker密码中的哈希问题?