当我尝试运行使用rimraf的节点项目时,在docker容器中,我收到无法找到模块rimraf的错误。它已安装,可以在我的package.json中找到。如果我在本地运行我的应用程序,一切正常。 错误日志:
Error: Cannot find module 'rimraf'
node_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
node_1 | at Function.Module._load (internal/modules/cjs/loader.js:497:25)
node_1 | at Module.require (internal/modules/cjs/loader.js:626:17)
node_1 | at require (internal/modules/cjs/helpers.js:20:18)
node_1 | at Object.<anonymous> (/usr/src/app/controllers/products.js:5:16)
node_1 | at Module._compile (internal/modules/cjs/loader.js:678:30)
node_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
node_1 | at Module.load (internal/modules/cjs/loader.js:589:32)
node_1 | at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
node_1 | at Function.Module._load (internal/modules/cjs/loader.js:520:3)
node_1 | at Module.require (internal/modules/cjs/loader.js:626:17)
node_1 | at require (internal/modules/cjs/helpers.js:20:18)
node_1 | at Object.<anonymous> (/usr/src/app/expressRoutes/productRoutes.js:6:26)
node_1 | at Module._compile (internal/modules/cjs/loader.js:678:30)
node_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
node_1 | at Module.load (internal/modules/cjs/loader.js:589:32)
我的dockerfile:
FROM node
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package.json /usr/src/app
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app
# Expose the port the app runs in
EXPOSE 4000
# Serve the app
CMD ["npm", "start"]
任何帮助/建议为什么会这样? Github链接:https://github.com/isaacs/rimraf/issues/171
我的docker-compose.yml问。
version: '2'
services:
node:
image: some-private-repo/node_application:latest
ports:
- "4000:4000"
links:
- mongo
environment:
- MONGO_URL=mongodb://mongo:27017/mydb
networks:
- network
depends_on:
- mongo
mongo:
image: mongo:latest
ports:
- "27017:27017"
networks:
- network
网络: 网络: 司机:桥梁