Dockerfile CMD命令未执行

发布于 2025-02-08 04:03:51 字数 373 浏览 1 评论 0原文

我写了这个Dockerfile。它应该构建应用程序,然后将其运行到我创建的容器中,但不起作用。当我使用该图像创建一个容器时,cmd命令不执行,并且网站未运行。但是,当i exec容器并手动键入它时,它起作用。

FROM node:16 as builder
WORKDIR /app
COPY ./package*.json ./
RUN npm install
COPY . .
RUN npm run build

FROM node:16
WORKDIR /app
RUN npm install serve
COPY --from=builder /app/build .
CMD ["npx", "serve"]

I wrote this Dockerfile. It should build the app and then run it into the container which I create, but it doesn't work. When I create a container with that image, CMD commands is not execute and the site is not running. But it works when I exec the container and type it manually.

FROM node:16 as builder
WORKDIR /app
COPY ./package*.json ./
RUN npm install
COPY . .
RUN npm run build

FROM node:16
WORKDIR /app
RUN npm install serve
COPY --from=builder /app/build .
CMD ["npx", "serve"]

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文