简体   繁体   English

Docker 节点 js 容器无法运行

[英]Docker node js container wont run

My page layout I want to make my API file dockerize but when I try to run my image its closes instantly I'm thinking my docker file is wrong but I don't know how I fix我的页面布局我想让我的 API 文件 dockerize 但是当我尝试运行我的图像时它会立即关闭我认为我的 docker 文件是错误的,但我不知道如何修复

My docker file:我的 docker 文件:

FROM node:15
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY ./api /usr/src/app
COPY .env /usr/src/app
EXPOSE 5000
CMD ["npm", "start"]

and when I run to image closes instantly当我跑到图像时立即关闭

Docker log Docker 日志


> malice-api@1.0.0 start
> node ./api/index.js

node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/usr/src/app/api/index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm notice
npm notice New minor version of npm available! 7.7.6 -> 7.14.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.14.0>
npm notice Run `npm install -g npm@7.14.0` to update!
npm notice

> malice-api@1.0.0 start
> node ./api/index.js

node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/usr/src/app/api/index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

From the docs文档

If <src> is a directory, the entire contents of the directory are copied, including filesystem metadata.The directory itself is not copied, just its contents.如果<src>是目录,则复制目录的全部内容,包括文件系统元数据。不复制目录本身,仅复制其内容。

So, try to change the second copy instruction to因此,尝试将第二个copy指令更改为

COPY api /usr/src/app/api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM