带有烧瓶的容器和postgres之间的通信错误



我在尝试使用flask、nginx和postgres在容器之间建立连接时遇到了一个问题。出现以下错误:

flask       | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
flask       |   Is the server running on host "localhost" (127.0.0.1) and accepting
flask       |   TCP/IP connections on port 5454?
flask       | could not connect to server: Cannot assign requested address
flask       |   Is the server running on host "localhost" (::1) and accepting
flask       |   TCP/IP connections on port 5454?

烧瓶连接:

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:admin@localhost:5454/plataforma_testes'

码头工人组成:

version: "3.3"
services:
flask:
build: ./flask
container_name: flask
restart: always
environment: 
- APP_NAME=PlataformDeTestes
- DB_USERNAME=postgres
expose:
- 8080
links:
- database
depends_on:
- database
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
database:
image: postgres:10
env_file: postgres/.env
ports:
- "5454:5432"
volumes:
- /docker/volumes/postgres:/var/lib/postgresql/

有人有什么建议吗?

更改:

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:admin@localhost:5454/plataforma_testes'

至:

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:admin@database:5432/plataforma_testes'

localhostdatabase并且端口到5432然后再到docker-compose up

谢谢!它使用工作

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:admin@database:5432/plataforma_testes'

database:
image: postgres:10
env_file: postgres/.env
volumes:
- /docker/volumes/postgres:/var/lib/postgresql/data

最新更新