gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:05 25 4
gpt4 key购买 nike

如何使用 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 给我这个:

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 文件。

关于node.js - 如何使用 docker-compose 运行 Express 和 Mongo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44959857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com