###前提・実現したいこと
dockerの練習として、docker-composeでpostgresqlを扱おうとしています。
###発生している問題・エラーメッセージ
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@3.10.3
3 info using node@v6.2.2
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle dockertest@1.0.0prestart: dockertest@1.0.0prestart: no script for prestart, continuing
6 silly lifecycle dockertest@1.0.0
7 info lifecycle dockertest@1.0.0start: dockertest@1.0.0start: unsafe-perm in lifecycle true
8 verbose lifecycle dockertest@1.0.0
9 verbose lifecycle dockertest@1.0.0start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/usr/src/app/node_modules/.bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binstart: CWD: /usr/src/app
10 verbose lifecycle dockertest@1.0.0
11 silly lifecycle dockertest@1.0.0start: Args: [ '-c', 'node index.js' ]start: Returned: code: 1 signal: null
12 silly lifecycle dockertest@1.0.0
13 info lifecycle dockertest@1.0.0~start: Failed to exec start script
14 verbose stack Error: dockertest@1.0.0 start: node index.js
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid dockertest@1.0.0
16 verbose cwd /usr/src/app
17 error Linux 4.9.6-moby
18 error argv "/usr/bin/node" "/usr/bin/npm" "start"
19 error node v6.2.2
20 error npm v3.10.3
21 error code ELIFECYCLE
22 error dockertest@1.0.0 start: node index.js
22 error Exit status 1
23 error Failed at the dockertest@1.0.0 start script 'node index.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the dockertest package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node index.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs dockertest
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls dockertest
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
###該当のソースコード
docker-compose.yml
version: '2' services: web: build: . volumes: - ./web:/usr/src/app ports: - "3000:3000" links: - db volumes_from: - data db: image: postgres ports: - "1234:1234" volumes_from: - data data: image: busybox volumes: - .data:/data
Dockerfile
FROM mhart/alpine-node:6.2.2 RUN apk update && apk add git RUN npm install -g pm2 ADD ./web /usr/src/app WORKDIR /usr/src/app RUN ["npm", "install"] ENTRYPOINT ["npm", "start"]
web/index.js
javascript
1var pg = require('pg'); 2var async = require('async'); 3 4var connectString = "tcp://postgres@localhost:1234/data"; 5 6pg.connect(connectString, function(err, client) { 7 if (err) { 8 console.log('Connection Error:', err); 9 throw err; 10 } else { 11 console.log('Connected'); 12 } 13});
###試したこと
上記のコードを実行したのですが、どうにも繋がりませんでした。
どのように直せば繋がるか教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/04 13:05
2017/02/07 04:31