NodeJS:无法从另一个容器连接到postgreSQL容器

我有一个NodeJS应用程序的容器,它必须链接到另一个容器与Postgres数据库。 我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”。

当我inputdocker-compose并尝试链接容器时,在从控制台发出以下消息之后:

 [INFO] console - postgres://user:password@localhost:5432/bucket 

我得到这个错误:

 Error: Connection terminated at [object Object].<anonymous> 

/node_modules/massive/node_modules/deasync/index.js:46

哪里有问题?

你定义了两次command ,这意味着你的wait-for-command.shsh start.sh覆盖,而且在PostgreSQL准备接受连接之前它可能正在运行。