我有Dockerfile来部署我的前端,这是有反应的。 这就是我的dockerfile中的内容。
# Stage 1
FROM node:8 as react-build
WORKDIR /app
COPY . ./
RUN yarn
RUN yarn build
# Stage 2 - the production environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=react-build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
当我运行$ docker build . -t frontend
时
我在步骤8遇到错误,无法复制nginx.conf
Step 8/10 : COPY --from=react-build /app/build /usr/share/nginx/html
COPY failed: stat /var/lib/docker/overlay2/fef4deafd532bb0aa7eaea50ae25412e93f7972eab3a0579fe494de444d86a0b/merged/app/build: no such file or directory
但是nginx conf文件存在,并且我不知道那里发生了什么,有人可以启发我发生了什么吗? http://prntscr.com/l2to47这是我的项目结构,明确表示存在nginx.conf,但Docker无法找到它。
答案 0 :(得分:0)
它不会复制getBody #+ [...]
文件,也不会找到在nginx.conf
阶段生成的数据。
我曾经遇到过同样的问题,我解决了更改react-build
目录的问题,因为原来的目录公开为WORKDIR
(看来在多阶段构建中它不起作用) 。尝试另一种,例如:
VOLUME
看看是否能解决问题。