【问题标题】:How to run Express and Mongo using docker-compose如何使用 docker-compose 运行 Express 和 Mongo
【发布时间】:2017-07-06 22:29:40
【问题描述】:

如何使用 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

谁能告诉我我的撰写文件有什么问题?

【问题讨论】:

    标签: node.js mongodb express docker docker-compose


    【解决方案1】:

    您没有指定 WORKDIR。就像在 Dockerfile 中一样:

    WORKDIR /application
    

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

    working_dir: /application
    

    npm 会在那里寻找 package.json 文件。

    【讨论】:

    • 不工作,仍然是同样的问题,但有另一个路径,现在:npm ERR! enoent ENOENT:没有这样的文件或目录,打开'/application/package.json'
    • 你的 package.json 文件在哪里?
    • 将图像:节点:7.7.2-alpine 更改为 biuld:。一切正常,当然也添加 working_dir: /application,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    相关资源
    最近更新 更多