【发布时间】:2020-02-21 14:05:28
【问题描述】:
我认为这个问题应该很容易解决,但我正在拉扯我的头发。我有以下 docker-compose:
version: "3"
services:
pg-db:
image: postgres:11
environment:
POSTGRES_PASSWORD: "postgres"
POSTGRES_USER: "postgres"
POSTGRES_DB: "postgres"
ports:
- 5432:5432
#network_mode: host
然后我运行docker-compose up 并启动容器
pg-db_1_78e7ec4a95e6 | 2020-02-21 13:53:53.928 UTC [1] LOG: database system is ready to accept connections
我可以用 docker exec 连接到它
docker exec -it docker_pg-db-compose_1_78e7ec4a95e6 psql -h pg-db -U postgres postgres
但我无法通过“裸”psql 连接到它:
psql postgresql://postgres:postgres@localhost:5432/postgres
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
psql postgresql://postgres:postgres@pg-dg:5432/postgres
psql: could not translate host name "pg-db" to address: Name or service not known
我已尝试使用 network_mode,但没有帮助。
【问题讨论】:
标签: postgresql docker docker-compose psql