本文介绍了无法使用 docker-compose 为 Postgres 设置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 Docker-compose 为 Postgres 设置密码.Postgres 在没有密码的情况下加载,默认用户名postgres",似乎没有应用以下环境变量.下面是我的 docker-compose.yml 文件的数据库服务:(版本 3)

I am not able to set Password for Postgres using Docker-compose. Postgres is loading without password and with the default user name "postgres", non of the environment variables below seems to applied. below is the db service of my docker-compose.yml file: (version 3)

db:
  image: postgres
  container_name: postgres
  environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: db
  restart: unless-stopped
  volumes:
    - ./postgres-data:/var/lib/postgresql/data
  ports:
    - "5432:5432"

请注意,我也尝试使用-POSTGRES_USER=",但没有成功

Note I tried using the "-POSTGRES_USER=" as well, it didn't work

另外,我删除了所有旧容器/卷.

Also, I deleted all old containers/volumes.

有什么想法吗?

推荐答案

问题应该是附加的卷.当您的容器启动时,它将添加您提供给他的凭据,但随后将附加该卷,这将导致此信息被重写.

The problem should be with the volume attached. When your container start it will add the credentials you give him, but then the volume will be attached and that will cause this information being rewritten.

有关更多信息,请查看 https://github.com/docker-library/postgres/issues/203#issuecomment-255200501.

For more information have a look at https://github.com/docker-library/postgres/issues/203#issuecomment-255200501.

这篇关于无法使用 docker-compose 为 Postgres 设置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 11:37
查看更多