在執行 docker-compose 時,我嘗試啟動 PostgreSQL Docker 容器失敗。如果我改為使用 docker run ,我可以連接到它。我不知道有什么區別。我對 compose 的意圖是讓它創建一個可用于開發的資料庫,并且我可以通過用戶 postgres 連接到該資料庫。
碼頭工人-compose.yml:
version: '3.7'
services:
my_app:
build:
dockerfile: ./dockerfile-my-app
context: .
command: tail -f /dev/null
depends_on:
- db
env_file: ./.env.development
ports:
- "8080:8080"
volumes:
- /c/Users/woodsman/linux-mint-woodsman/home/dev:/home/dev
db:
image: postgres:latest
env_file: ./.env.development
environment:
- POSTGRES_USER= postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=helloworld
- PGDATA=/var/lib/postgresql/data/helloworld2/
ports:
- "5432:5432"
restart: "no"
volumes:
- /c/Users/woodsman/linux-mint-woodsman/dbdata:/var/lib/postgresql/data/pgdata
volumes:
dbdata:
嘗試jdbc:postgresql://localhost:5432/helloworld使用用戶 postgres 和密碼 postgres 連接。請原諒您可能察覺到的任何安全問題。這將在開發中得到加強,并且在部署到生產中時會更加安全。
SquirrelSQL 報告的錯誤是:
hello-world: FATAL: password authentication failed for user "postgres"
class org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
影像哈希碼為:9dbc24674f25eb449df11179ed3717c47348fb3aa985ae14b3936d54c2c09dde
>docker logs c4c2
2022-05-16 05:28:50.560 UTC [1] LOG: starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110 1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-05-16 05:28:50.560 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-05-16 05:28:50.560 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-05-16 05:28:50.564 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-05-16 05:28:50.571 UTC [63] LOG: database system was shut down at 2022-05-16 05:28:50 UTC
2022-05-16 05:28:50.579 UTC [1] LOG: database system is ready to accept connections
2022-05-16 05:29:17.184 UTC [70] FATAL: password authentication failed for user "postgres"
2022-05-16 05:29:17.184 UTC [70] DETAIL: Role "postgres" does not exist.
Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
2022-05-16 05:36:41.983 UTC [78] FATAL: password authentication failed for user "postgres"
2022-05-16 05:36:41.983 UTC [78] DETAIL: Role "postgres" does not exist.
Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
我希望有一個基于 Docker 的答案。如果有一些 PostgreSQL 命令我需要執行(或不執行),請告訴我如何通過 Docker 傳遞它。
謝謝,樵夫
uj5u.com熱心網友回復:
您的主要錯誤是:
角色“postgres”不存在。
似乎是因為 docker-compose.yml 中的空格:
- POSTGRES_USER=postgres
在第一次啟動 postgres 時已初始化,因此當您更改變數中的“POSTGRES_USER”時,不會創建角色。您可以洗掉您的卷并再次啟動 docker-compose。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/476021.html
標籤:PostgreSQL 码头工人 码头工人撰写
