Docker Nodejs 多阶段构建错误。未找到距离
Docker Nodejs Multi Stage build Error. Dist not found
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
CMD ["yarn", "run", "build"]
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
这是我的 dockerfile。当我构建它时,我收到一条错误消息,提示未找到 dist。
COPY failed: stat /var/lib/docker/overlay2/e397e0fd69733a25f53995c12dfbab7d24ce20867fede11886d49b9537976394/merged/usr/src/app/dist: no such file or directory
知道为什么会这样吗?
非常感谢任何帮助。
谢谢。
这里的问题是在 CMD ["yarn", "run", "build"]
处使用 CMD
而不是 RUN
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
RUN yarn run build
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
的文档
来自关于 CMD
的文档:
The main purpose of a CMD
is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT
instruction as well.
来自关于 RUN
的文档:
The RUN
instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
如您所见,CMD
在 运行 执行容器时 运行 执行,但 RUN
命令用于构建 docker 图像
下次如何调试?
在您的 Dockerfile 中,您基本上可以 运行 映像的任何可执行部分。所以要检查 dist 文件夹是否存在或者它的内容是什么,你可以使用 ls
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
RUN yarn run build
RUN ls -la dist
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
CMD ["yarn", "run", "build"]
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
这是我的 dockerfile。当我构建它时,我收到一条错误消息,提示未找到 dist。
COPY failed: stat /var/lib/docker/overlay2/e397e0fd69733a25f53995c12dfbab7d24ce20867fede11886d49b9537976394/merged/usr/src/app/dist: no such file or directory
知道为什么会这样吗?
非常感谢任何帮助。
谢谢。
这里的问题是在 CMD ["yarn", "run", "build"]
CMD
而不是 RUN
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
RUN yarn run build
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
的文档
来自关于 CMD
的文档:
The main purpose of a
CMD
is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify anENTRYPOINT
instruction as well.
来自关于 RUN
的文档:
The
RUN
instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
如您所见,CMD
在 运行 执行容器时 运行 执行,但 RUN
命令用于构建 docker 图像
下次如何调试?
在您的 Dockerfile 中,您基本上可以 运行 映像的任何可执行部分。所以要检查 dist 文件夹是否存在或者它的内容是什么,你可以使用 ls
FROM node:14.9-stretch-slim AS build
WORKDIR /usr/src/app
COPY ./package.json ./
RUN yarn
COPY . .
RUN yarn run build
RUN ls -la dist
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html