简体   繁体   English

用户“postgres”的 Docker 密码认证失败

[英]Docker password authentication failed for user “postgres”

I'm writing a docker-compose file to launch some services.我正在编写一个 docker-compose 文件来启动一些服务。 But the db service is a trouble maker, I always get this error:但是 db 服务是个麻烦制造者,我总是得到这个错误:

FATAL: password authentication failed for user "postgres" DETAIL: Password does not match for user "postgres". Connection matched pg_hba.conf line 95: "host all all all md5"

I've read a lot of threads, and I've correctly set the POSTGRES_USER and POSTGRES_PASSWORD.我已经阅读了很多线程,并且我已经正确设置了 POSTGRES_USER 和 POSTGRES_PASSWORD。 I have also remove the previous volumes and container to force postgresql to re-init the password.我还删除了以前的卷和容器以强制 postgresql 重新初始化密码。 But I can't figure out why it's still not working.但我不知道为什么它仍然不起作用。

So what is the correct way to force the re-initialization of the postgresql image.那么强制重新初始化 postgresql 映像的正确方法是什么。 So I would be able to connect to my database.所以我将能够连接到我的数据库。

I've seen that this error: Connection matched pg_hba.conf line 95: "host all all all md5" , and I've heard about the postgres conf file.我已经看到这个错误: Connection matched pg_hba.conf line 95: "host all all all md5" ,我听说过 postgres conf 文件。 But it's an official container it's supposed to work, isn't it?但它是一个官方容器,它应该可以工作,不是吗?

version: '3'
services:
  poll:
    build: poll
    container_name: "poll"
    ports:
      - "5000:80"
    networks:
      - poll-tier
    environment:
      - REDIS_HOST=redis
    depends_on:
      - redis

  worker:
    build: worker
    container_name: "worker"
    networks:
      - back-tier
    environment:
      - REDIS_HOST=redis
      - POSTGRES_HOST=db
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=root
    depends_on:
      - redis
      - db

  redis:
    image: "redis:alpine"
    container_name: "redis"
    networks:
      - poll-tier
      - back-tier

  result:
    build: result
    container_name: "result"
    ports:
      - "5001:80"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=root
      - POSTGRES_HOST=db
      - RESULT_PORT=80
    networks:
      - result-tier
    depends_on:
      - db

  db:
    image: "postgres:alpine"
    container_name: "db"
    restart: always
    networks:
      - back-tier
      - result-tier
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=root
      - POSTGRES_DB=postgres

volumes:
  db-data:
    driver: local

networks:
  poll-tier: {}
  back-tier: {}
  result-tier: {}

I'm expected to get the db connected, and not password authentication failed for user "postgres" .我希望连接数据库,而不是password authentication failed for user "postgres"

Make sure your APPs (not the database container) are actually using the POSTGRES_USER and POSTGRES_PASSWORD variables.确保您的应用程序(而不是数据库容器)实际上正在使用POSTGRES_USERPOSTGRES_PASSWORD变量。 I suspect they are looking for something like DB_USER or similar and so aren't getting the right values in.我怀疑他们正在寻找类似DB_USER或类似的东西,因此没有得到正确的值。

By default, every PostgreSQL database driver and admin tool defaults to the postgres user.默认情况下,每个 PostgreSQL 数据库驱动程序和管理工具默认为postgres用户。 This may explain why the error message complains about postgres even if the environment variable isn't being used.这可以解释为什么即使没有使用环境变量,错误消息也会抱怨postgres

A good way to verify is to change all references to the database user in the docker-compose file to something like postgres2 .验证的一个好方法是将 docker-compose 文件中对数据库用户的所有引用更改为类似postgres2的内容。 I suspect you'll still see apps complaining that password auth failed for postgres .我怀疑您仍然会看到应用程序抱怨postgres的密码验证失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM