如何使用docker-compose运行Express和Mongo

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

我的docker-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看起来工作正常:

 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 npm@4.1.2 express-container | npm info using node@v7.7.2 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 

有人能告诉我什么是我的撰写文件错误?

您没有指定WORKDIR。 正如这在Dockerfile中:

 WORKDIR /application 

或者只在docker-compose.yml中相应的服务:

 working_dir: /application 

npm将在那里查找package.json文件。