不能将图像作为容器运行

发布于 2025-02-06 01:24:04 字数 810 浏览 0 评论 0原文

我成功地创建了项目的图像。但是,当我想将此映像作为容器运行时,我会收到以下错误,

> [email protected] start
> react-scripts start

sh: react-scripts: not found

我的docker文件就是这样:

FROM node:16.14-alpine3.14 

WORKDIR /frontend

COPY package.json .

RUN npm install -g [email protected]

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]

package.json文件是这样的:

"scripts": {
    "start": "react-scripts start",
     .
     .
     .

  }

我删除了node_module并以这种方式尝试过,但是它不起作用,我做了很多这样的事情,但行不通。如果您能提供帮助,我会很高兴。

I have successfully created the image of the project. But when I want to run this image as a container, I get the following error

> [email protected] start
> react-scripts start

sh: react-scripts: not found

My docker file is like that :

FROM node:16.14-alpine3.14 

WORKDIR /frontend

COPY package.json .

RUN npm install -g [email protected]

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]

The Package.json file is like that :

"scripts": {
    "start": "react-scripts start",
     .
     .
     .

  }

I deleted node_module and tried it that way, but it didn't work, I did many things like this, but it doesn't work. I would be pleased if you could help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎的声音 2025-02-13 01:24:04

您不是在package.json中安装依赖项。添加运行npm install这样

FROM node:16.14-alpine3.14 

WORKDIR /frontend

COPY package.json .

RUN npm install -g [email protected]
RUN npm install

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]

You're not installing the dependencies from package.json. Add RUN npm install like this

FROM node:16.14-alpine3.14 

WORKDIR /frontend

COPY package.json .

RUN npm install -g [email protected]
RUN npm install

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文