在我的項目中,我有一個Dockerfile
與nodejs
圖像。在docker-compose.yml
文件我有兩個服務:server
從Dockerfile
和db
建立,它使用postgres
圖像。docker-compose執行命令在主要服務取決於其他服務
Dockerfile
獲取圖像,爲該項目創建一個目錄,運行npm install
並設置CMD ["npm", "start"]
。
我docker-compose.yml
的內容:
version: "2"
services:
server:
build: .
ports:
- "5000:5000"
volumes:
- ./:/usr/src/app
links:
- db
db:
image: postgres:9.6.2
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgres
restart: always
environment:
POSTGRES_PASSWORD: devel
POSTGRES_USER: devel
POSTGRES_DB: devel
volumes:
db_data:
在我的項目,我使用db-migrate
與db-migrate-pg
司機,當我嘗試執行遷移,我得到了一個錯誤:7
[ERROR] Error: connect ECONNREFUSED 127.0.0.1:5432
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1136:14)
npm info lifecycle [email protected]~migrate-up: Failed to exec migrate-up script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] migrate-up: `db-migrate up`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] migrate-up script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-07-12T17_31_10_049Z-debug.log
的數據庫的配置是正確的,因爲我可以在PgAdmin上使用它。我不知道如何訪問指出錯誤的文件,因爲容器在結束執行後停止。
編輯:
這是從指定的文件輸出錯誤齊全:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'migrate-up' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'premigrate-up', 'migrate-up', 'postmigrate-up' ]
5 info lifecycle [email protected]~premigrate-up: [email protected]
6 silly lifecycle [email protected]~premigrate-up: no script for premigrate-up, continuing
7 info lifecycle [email protected]~migrate-up: [email protected]
8 verbose lifecycle [email protected]~migrate-up: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~migrate-up: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/src/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
10 verbose lifecycle [email protected]~migrate-up: CWD: /usr/src/app
11 silly lifecycle [email protected]~migrate-up: Args: [ '-c', 'db-migrate up' ]
12 silly lifecycle [email protected]~migrate-up: Returned: code: 1 signal: null
13 info lifecycle [email protected]~migrate-up: Failed to exec migrate-up script
14 verbose stack Error: [email protected] migrate-up: `db-migrate up`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:283:16)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at EventEmitter.emit (events.js:213:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at ChildProcess.emit (events.js:213:7)
14 verbose stack at maybeClose (internal/child_process.js:887:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid [email protected]
16 verbose cwd /usr/src/app
17 verbose Linux 4.8.0-58-generic
18 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "migrate-up"
19 verbose node v8.0.0
20 verbose npm v5.0.0
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] migrate-up: `db-migrate up`
23 error Exit status 1
24 error Failed at the [email protected] migrate-up script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
是否需要將端口添加到'links'部分的'db'行? 我更新了我的問題以添加文件的輸出。 – abaracedo
@abaracedo,不,你沒有。我也發佈了 – Robert
我也得到了同樣的錯誤:( – abaracedo