简体   繁体   English

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

[英]How to run Express and Mongo using docker-compose

How to run Express and MongoDB using docker-compose? 如何使用docker-compose运行Express和MongoDB?

My docker-compose.yml looks like this: 我的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

After run docker-compose up mongo looks work fine: 运行docker-compose up mongo后,看起来工作正常:

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

But express give me this: 但是表达给我这个:

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

Can someone tell me what's wrong with my compose file? 有人可以告诉我我的撰写文件出了什么问题吗?

You lack to specify the WORKDIR. 您无需指定WORKDIR。 As this in Dockerfile: 在Dockerfile中是这样的:

WORKDIR /application

Or just in docker-compose.yml in the corresponding service: 或者只是在相应服务的docker-compose.yml中:

working_dir: /application

npm will look there for the package.json file. npm将在其中查找package.json文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM