Postgres服务一直重新启动

3
我正在运行以下带有Postgres服务的Docker Compose文件:

docker-compose.yml:

version: "3"
services:
  db:
    image: postgres:latest
    restart: always
    container_name: dev_db
    environment:
        - POSTGRES_HOST_AUTH_METHOD = trust
    ports:
    - 5435:5432
    volumes:
    - dev_data:/var/lib/postgresql/data
    - ./dbscripts/postgres:/docker-entrypoint-initdb.d    
volumes:
   dev_data:

然而,我的容器一直在重启,当检查日志时,我收到了以下消息:
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.
       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

有人知道这个问题的来源吗?
2个回答

3

您定义的环境变量存在语法问题。请尝试使用以下 docker-compose.yml 文件:

version: "3"
services:
  db:
    image: postgres:latest
    restart: always
    container_name: dev_db
    environment:
        - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
    - 5435:5432
    volumes:
    - dev_data:/var/lib/postgresql/data
    - ./dbscripts/postgres:/docker-entrypoint-initdb.d    
volumes:
   dev_data:
docker-compose up 命令的日志
docker-compose up
Creating network "test_default" with the default driver
Pulling db (postgres:latest)...
latest: Pulling from library/postgres
afb6ec6fdc1c: Already exists
51be5f829bfb: Pull complete
e707c08f571a: Pull complete
98ddd8bce9b5: Pull complete
5f16647362a3: Pull complete
5d56cdf9ab3b: Pull complete
2207a50ca41d: Pull complete
a51d14a628f3: Pull complete
24dcb11335d0: Pull complete
54cc759cb0bb: Pull complete
debc11d66570: Pull complete
3ffd0589b5fc: Pull complete
490b7ee49751: Pull complete
3511c6be34a0: Pull complete
Digest: sha256:ec7cfff29672a2f676c11cc53ae7dafe63a57ccefc2b06ea423493227da29b9c
Status: Downloaded newer image for postgres:latest
Creating dev_db ... done
Attaching to dev_db
dev_db | ********************************************************************************
dev_db | WARNING: POSTGRES_HOST_AUTH_METHOD has been set to "trust". This will allow
dev_db |          anyone with access to the Postgres port to access your database without
dev_db |          a password, even if POSTGRES_PASSWORD is set. See PostgreSQL
dev_db |          documentation about "trust":
dev_db |          https://www.postgresql.org/docs/current/auth-trust.html
dev_db |          In Docker's default configuration, this is effectively any other
dev_db |          container on the same system.
dev_db |
dev_db |          It is not recommended to use POSTGRES_HOST_AUTH_METHOD=trust. Replace
dev_db |          it with "-e POSTGRES_PASSWORD=password" instead to set a password in
dev_db |          "docker run".
dev_db | ********************************************************************************
dev_db | The files belonging to this database system will be owned by user "postgres".
dev_db | This user must also own the server process.
dev_db |
dev_db | The database cluster will be initialized with locale "en_US.utf8".
dev_db | The default database encoding has accordingly been set to "UTF8".
dev_db | The default text search configuration will be set to "english".
dev_db |
dev_db | Data page checksums are disabled.
dev_db |
dev_db | fixing permissions on existing directory /var/lib/postgresql/data ... ok
dev_db | creating subdirectories ... ok
dev_db | selecting dynamic shared memory implementation ... posix
dev_db | selecting default max_connections ... 100
dev_db | selecting default shared_buffers ... 128MB
dev_db | selecting default time zone ... Etc/UTC
dev_db | creating configuration files ... ok
dev_db | running bootstrap script ... ok
dev_db | performing post-bootstrap initialization ... ok
dev_db | syncing data to disk ... ok
dev_db |
dev_db |
dev_db | Success. You can now start the database server using:
dev_db |
dev_db |     pg_ctl -D /var/lib/postgresql/data -l logfile start

0

我认为 docker 无法读取您的环境变量,因为它没有正确设置。 正确的语法是

environment:
    - "POSTGRES_HOST_AUTH_METHOD=trust"

好的,那么请尝试在这里给出的解决方案。 - JessePinkman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接