这是我第一次使用docker-compose。我有这个文件:
db:
image: postgres
ports:
- "3600:5432"
environment:
- POSTGRES_HOST=127.0.0.1
- POSTGRES_DB=db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres1
api:
build: .
ports:
- "4500:4500"
links:
- db
现在我必须将其翻译为版本3:
version: "3"
services:
db:
image: postgres
ports:
- "3600:5432"
environment:
POSTGRES_HOST: "127.0.0.1"
POSTGRES_DB: "db"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres1"
api:
build: .
ports:
- "4500:4500"
links:
- db
这是一个链接了postgres的节点应用程序,当我阅读如何连接到数据库时,我这样做:
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('./config/prod.json', 'utf8'));
config.database = {
host: (process.env.TRAVELOOCAPI_DB_1_PORT_5432_TCP_ADDR || "localhost"),
port: (process.env.TRAVELOOCAPI_DB_1_PORT_5432_TCP_PORT || "5432"),
db: (process.env.TRAVELOOCAPI_DB_1_ENV_POSTGRES_DB || 'myapp'),
dialect: 'postgres',
user: (process.env.TRAVELOOCAPI_DB_1_ENV_POSTGRES_USER || 'pg'),
pass: (process.env.TRAVELOOCAPI_DB_1_ENV_POSTGRES_PASSWORD || 'password'),
};
它适用于第一个版本,但它不适用于第二个版本。没有任何进程。与postgres有关。
我做错了什么?
谢谢!