用户“postgres”的密码不匹配

kmi*_*3sd 7 postgresql docker dockerfile docker-compose

我正在尝试在我的 docker-compose 中提升服务以使用 postgres,我可以正确提升容器,问题是它不允许我使用我在环境变量中设置的密码进行身份验证

这是我的 docker-compose 服务:

version: "3"
services:
  api:
    build:
      context: .
      dockerfile: docker/nodejs/Dockerfile
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    links:
      - postgresql

  postgresql:
    image: postgres:11-alpine
    restart: always
    environment:
      POSTGRES_PASSWORD: 00000000
    volumes:
      - ~/docker/postgresql:/var/lib/postgresql/data
    ports:
      - "5432:5432"
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?我试图进入 pgadmin。在控制台中向我显示错误:

password authentication failed for user "postgres"
Password does not match for user "postgres".
Run Code Online (Sandbox Code Playgroud)

小智 8

Postgres 密码是在数据库第一次初始化时设置的(当 var/lib/postgresql/data 文件夹为空时)。由于您之前可能使用不同的密码运行 docker-compose,因此新密码不会生效。要解决此问题,请删除主机中的卷,并让 docker-compose 在下次运行 docker-compose up 时自动重新创建它。请注意,删除此卷将删除 PostgreSQL 中存储的所有数据


小智 -1

如果您不是第一次运行它,那么您可能已经更改了它。您可以手动编辑pg_hba.conf文件并设置信任授权类型