【发布时间】:2017-03-11 23:00:22
【问题描述】:
我无法从运行节点和 Sequelize 的单独 docker 服务连接到默认 Postgres 映像。
我假设我的容器设置不正确,而且我的连接信息也可能不正确,因为我在运行 docker-compose --build 时无法使用连接信息连接到我的数据库:
Host: 0.0.0.0
Port: 5432
User: guy
Password: password
Database: engauge
错误信息是
Unable to connect to the database: { SequelizeConnectionRefusedError: connect ECONNREFUSED 0.0.0.0:5432
at /usr/src/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:98:20
我正在运行一个看起来像这样的 YML 文件
version: '2' # specify docker-compose version
# Define the services/containers to be run
services:
web: # name of the first service
build: . # specify the directory of the Dockerfile
ports:
- "3000:3000" # specify port forewarding
links:
- database
database: # name of the third service
image: postgres # specify image to build container from
ports:
- "5432:5432" # specify port forewarding
environment:
- POSTGRES_USER:'guy'
- POSTGRES_PASSWORD:'password'
- POSTGRES_DB:'engauge'
我的网络服务中的连接看起来像这样
const sequelize = new Sequelize('postgresql://guy:password@0.0.0.0/engauge');
【问题讨论】:
-
您只能在 0.0.0.0 上收听,无法连接。你试过127.0.0.1吗? (或者无论容器的 IP 地址是什么。)
标签: postgresql docker docker-compose sequelize.js