如何使用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
有人能告诉我我的撰写文件有什么问题吗?
答案 0 :(得分:0)
您没有指定WORKDIR。就像在Dockerfile中一样:
WORKDIR /application
或者只是在相应服务中的docker-compose.yml中:
working_dir: /application
npm将在那里查找package.json文件。