英文:
Cannot find module express: docker
问题
FROM node:18.16.0
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
我有这个Dockerfile,运行docker-compose up时出现错误:
Error: 无法找到模块'express'
我尝试更新了Dockerfile但没有成功
<details>
<summary>英文:</summary>
```docker
FROM node:18.16.0
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
I have this Dockerfile, when I run docker-compose up I get this error :
Error: Cannot find module 'express'
I tried updating the docker file but it did not work
答案1
得分: -1
"dependencies": {
"dependency1": "^v-xxx",
"dependency2": "^v-xxx",
"express": "^4.17.1" (version-4.17 is just an example)
}
不建议的方式:(在 Dockerfile 中更改这些)
RUN npm install
RUN npm install express
话虽如此,您需要以一种方式更改您的 Dockerfile,以便在服务器启动后不会退出。希望这有所帮助。
英文:
As pointed out by Sachin, we need to add express dependency in package.json file.
Better solution:
"dependencies": {
"dependency1": "^v-xxx",
"dependency2": "^v-xxx",
"express": "^4.17.1" (version-4.17 is just an example)
}
Not recommended way: (Alter these in Dockerfile)
RUN npm install
RUN npm install express
Being said that you need to alter your Dockerfile in a way that it will not exit once the server is started. Hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论