Node.js NodeJS:Can';t从另一个容器连接到postgreSQL容器
我有一个带有NodeJS应用程序的容器,它必须链接到另一个带有postgresdb的容器。我的Node.js NodeJS:Can';t从另一个容器连接到postgreSQL容器,node.js,postgresql,docker,Node.js,Postgresql,Docker,我有一个带有NodeJS应用程序的容器,它必须链接到另一个带有postgresdb的容器。我的docker compose.yml是: version: "3" services: postgres: image: "postgres:9.5.6-alpine" container_name: postgres volumes: - /shared_folder/postgresql:/var/lib/postgresql ports:
docker compose.yml
是:
version: "3"
services:
postgres:
image: "postgres:9.5.6-alpine"
container_name: postgres
volumes:
- /shared_folder/postgresql:/var/lib/postgresql
ports:
- "5432:5432"
web:
build: .
container_name: web
ports:
- "3000:3000"
links:
- postgres
depends_on:
- postgres
command: sh /usr/home/freebsd/wait-for-command.sh -c 'nc -z postgres 5432'
command: sh start.sh
在postgres容器上有一个名为“bucket”的数据库,由用户“user”拥有,密码为“password”
当我键入docker compose up并尝试链接容器时,在控制台的以下消息之后:
[INFO] console - postgres://user:password@localhost:5432/bucket
我得到这个错误:
Error: Connection terminated
at [object Object].<anonymous>
错误:连接已终止
在[对象]。
在/node\u modules/massive/node\u modules/deasync/index.js:46
问题出在哪里?您定义了两次
command
,这意味着您的等待命令。sh
被sh start.sh
覆盖,它可能在PostgreSQL准备接受连接之前运行