Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodeJS:Can';t从另一个容器连接到postgreSQL容器_Node.js_Postgresql_Docker - Fatal编程技术网

Node.js NodeJS:Can';t从另一个容器连接到postgreSQL容器

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:

我有一个带有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:
      - "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准备接受连接之前运行