运行容器错误时Docker错误:找不到模块' /home/app/server.js'
努力寻找问题
我会遇到以下错误,并在使用以下Dockerfile成功构建图像后 使用的命令
docker build -t my -app:1.0。
FROM node:13-alpine
# run something in the docker image
RUN mkdir -p /home/app
# this allows you to copy something from the host into docker image
COPY . /home/app
# inside the container it runs the command node server.js
# cmd is an entry point command, whereas run as used later
CMD ["node","/home/app/server.js"]
我已经运行以下命令来运行容器
Docker运行my-app:1.0
它会引发以下错误:
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
192:docker_compose_demo tech$ docker run my-app:1.0
internal/modules/cjs/loader.js:965
throw err;
^
Error: Cannot find module '/home/app/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:962:15)
at Function.Module._load (internal/modules/cjs/loader.js:838:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
我更改了Dockerfile的路径,但没有找到它。 有人可以告诉我在做什么错吗?
I'm getting the following error and I'm struggling to find the issue
After successfully building my image using the following Dockerfile
Command used
docker build -t my-app:1.0 .
FROM node:13-alpine
# run something in the docker image
RUN mkdir -p /home/app
# this allows you to copy something from the host into docker image
COPY . /home/app
# inside the container it runs the command node server.js
# cmd is an entry point command, whereas run as used later
CMD ["node","/home/app/server.js"]
I have run the following command to run the container
docker run my-app:1.0
it throws the following error:
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
192:docker_compose_demo tech$ docker run my-app:1.0
internal/modules/cjs/loader.js:965
throw err;
^
Error: Cannot find module '/home/app/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:962:15)
at Function.Module._load (internal/modules/cjs/loader.js:838:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I changed the path in the Dockerfile and yet is not finding it.
Can someone tell what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先是,使用
workdir
而不是运行mkdir
。为什么使用
workdir
?您可以参考下面的Dockerfile-
The first thing is, to use the
WORKDIR
instead of runningmkdir
.Why use
WORKDIR
?You can refer the below Dockerfile -