2017-07-06 92 views
1

如何使用docker-compose運行Express和MongoDB?如何使用docker-compose運行Express和Mongo

我的搬運工,compose.yml看起來是這樣的:

version: '3' 

services: 
    express: 
     image: node:7.7.2-alpine 
     container_name: express-container 
     ports: 
      - 3000:3000 
     volumes: 
      - .:/application/ 
      - /application/node_modules 
     links: 
      - mongodb 
     command: npm start 

    mongodb: 
     image: mongo:3.4.4 
     container_name: mongo-container 
     ports: 
      - 27017:27017 

運行後docker-compose up蒙戈看起來做工精細:

mongo-container | 2017-07-06T22:17:53.939+0000 I NETWORK [thread1] waiting for connections on port 27017 

但表達給我這個:

express-container | npm info it worked if it ends with ok 
express-container | npm info using [email protected] 
express-container | npm info using [email protected] 
express-container | npm ERR! Linux 4.9.27-moby 
express-container | npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 
express-container | npm ERR! node v7.7.2 
express-container | npm ERR! npm v4.1.2 
express-container | npm ERR! path /package.json 
express-container | npm ERR! code ENOENT 
express-container | npm ERR! errno -2 
express-container | npm ERR! syscall open 
express-container | 
express-container | npm ERR! enoent ENOENT: no such file or directory, open '/package.json' 
express-container | npm ERR! enoent ENOENT: no such file or directory, open '/package.json' 
express-container | npm ERR! enoent This is most likely not a problem with npm itself 
express-container | npm ERR! enoent and is related to npm not being able to find a file. 
express-container | npm ERR! enoent 
express-container | 
express-container | npm ERR! Please include the following file with any support request: 
express-container | npm ERR!  /npm-debug.log 
express-container exited with code 254 

燦有人告訴我我的撰寫文件有什麼問題?

回答

0

您缺少指定WORKDIR。由於這Dockerfile:

WORKDIR /application 

或者只是在相應的服務泊塢窗,compose.yml:

working_dir: /application 

NPM將在那裏尋找該文件的package.json。

+0

不工作,仍然是同樣的問題,但與另一個路徑,現在:npm ERR! enoent ENOENT:沒有這樣的文件或目錄,打開'/application/package.json' – Marcin

+0

你的package.json文件位於何處? – Robert

+0

更改圖片:節點:7.7.2 - 高山到陰影:。並且一切正常,當然也要加上working_dir:/ application,謝謝 – Marcin

相關問題