在执行docker-compose up时出现错误。
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
docker-compose.yml:-
version: '3'
services:
dcs_web:
build: .
depends_on:
- db
ports:
- "5000:5000"
db:
image: postgres:latest
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "5433:5433"
environment:
- 'POSTGRES_DB:dcmDB'
- 'POSTGRES_USER:postgres'
- 'POSTGRES_PASSWORD:admin'
volumes:
db-data:
在应用程序的 config.ini 文件中:
[DEFAULT]
DB_NAME = user
DB_PASSWORD = admin
DB_USER = postgres
DB_HOST = localhost
DB_PORT = 5433
DEBUG = True
我已经查看了'/var/lib/postgresql/data'位置,其中包含'listen adress = *'。但是我不知道如何处理这个问题。
db
。然而,这还不够,因为Kumar试图通过端口5433进行连接,而postgres正在监听端口5432。YAML文件的ports部分只将本地端口连接到容器端口。要使pg监听端口5433,请在service db中添加command: postgres -p 5433
。 - ChrisFal