Docker 和 Angular 生成阶段 `file does not exist` 错误在构建阶段的COPY命令

huangapple go评论93阅读模式
英文:

Docker and Angular prod `file does not exist` Error on stage build COPY command

问题

我不明白为什么Docker无法在容器中获取我的Angular构建文件夹。
你能看到以帮助我吗?

如果我使用Docker Compose命令构建,我会遇到这个错误。
以下是构建我的镜像并启动容器直到出错的所有步骤。

  1. 警告:您正在使用的Docker引擎正在以Swarm模式运行。
  2. Compose不使用Swarm模式将服务部署到Swarm中的多个节点。所有容器将安排在当前节点上。
  3. 要在整个Swarm中部署应用程序,请使用`docker stack deploy`
  4. 构建 linking-front
  5. 将构建上下文发送到Docker守护程序 425.6MB
  6. 步骤1/9FROM node:16.19.0 AS build
  7. ---> b22f8aab05da
  8. 步骤2/9WORKDIR /usr/src/app
  9. ---> 正在使用缓存
  10. ---> 5e2431455b65
  11. 步骤3/9COPY package.json package-lock.json ./
  12. ---> 正在使用缓存
  13. ---> 11d677269b0e
  14. 步骤4/9RUN npm install
  15. ---> 正在使用缓存
  16. ---> b5544be9159b
  17. 步骤5/9COPY . .
  18. ---> 正在使用缓存
  19. ---> 3403bfda57ca
  20. 步骤6/9RUN npm run build
  21. ---> 正在使用缓存
  22. ---> ae8e7960ac33
  23. 步骤7/9FROM nginx:1.23.3-alpine
  24. ---> 2bc7edbc3cf2
  25. 步骤8/9COPY nginx.conf /etc/nginx/nginx.conf
  26. ---> 正在使用缓存
  27. ---> beca38c7be94
  28. 步骤9/9COPY --from=build /usr/src/app/dist/linkingEducationSecurity-front /usr/share/nginx/html
  29. COPY 失败:stat usr/src/app/dist/linkingEducationSecurity-front: 文件不存在
  30. 错误:服务'linking-front'构建失败:构建失败
  1. ### 阶段1:构建 ###
  2. FROM node:16.19.0 AS build
  3. WORKDIR /usr/src/app
  4. COPY package.json package-lock.json ./
  5. RUN npm install
  6. COPY . .
  7. RUN npm run build
  8. ### 阶段2:运行 ###
  9. FROM nginx:1.23.3-alpine
  10. COPY nginx.conf /etc/nginx/nginx.conf
  11. COPY --from=build /usr/src/app/dist/linkingEducationSecurity-front /usr/share/nginx/html

我还使用了Docker Compose。

  1. version: '3.9'
  2. services:
  3. linking-front:
  4. build: ./linkingEducationSecurity-front/
  5. ports:
  6. - "8080:80"
  7. volumes:
  8. - type: bind
  9. source: ./linkingEducationSecurity-front/src/
  10. target: /app/src
英文:

i do not understand why docker cannot get my angular build folder in container.
Can you see that to help me?

Docker 和 Angular 生成阶段 `file does not exist` 错误在构建阶段的COPY命令

If i build with docker compose command i have this error.
Below are all the steps to build my image and launch my container until the error.

  1. WARNING: The Docker Engine you're using is running in swarm mode.
  2. Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
  3. To deploy your application across the swarm, use `docker stack deploy`.
  4. Building linking-front
  5. Sending build context to Docker daemon 425.6MB
  6. Step 1/9 : FROM node:16.19.0 AS build
  7. ---> b22f8aab05da
  8. Step 2/9 : WORKDIR /usr/src/app
  9. ---> Using cache
  10. ---> 5e2431455b65
  11. Step 3/9 : COPY package.json package-lock.json ./
  12. ---> Using cache
  13. ---> 11d677269b0e
  14. Step 4/9 : RUN npm install
  15. ---> Using cache
  16. ---> b5544be9159b
  17. Step 5/9 : COPY . .
  18. ---> Using cache
  19. ---> 3403bfda57ca
  20. Step 6/9 : RUN npm run build
  21. ---> Using cache
  22. ---> ae8e7960ac33
  23. Step 7/9 : FROM nginx:1.23.3-alpine
  24. ---> 2bc7edbc3cf2
  25. Step 8/9 : COPY nginx.conf /etc/nginx/nginx.conf
  26. ---> Using cache
  27. ---> beca38c7be94
  28. Step 9/9 : COPY --from=build /usr/src/app/dist/linkingEducationSecurity-front /usr/share/nginx/html
  29. COPY failed: stat usr/src/app/dist/linkingEducationSecurity-front: file does not exist
  30. ERROR: Service 'linking-front' failed to build : Build failed
  1. ### STAGE 1: Build ###
  2. FROM node:16.19.0 AS build
  3. WORKDIR /usr/src/app
  4. COPY package.json package-lock.json ./
  5. RUN npm install
  6. COPY . .
  7. RUN npm run build
  8. ### STAGE 2: Run ###
  9. FROM nginx:1.23.3-alpine
  10. COPY nginx.conf /etc/nginx/nginx.conf
  11. COPY --from=build /usr/src/app/dist/linkingEducationSecurity-front /usr/share/nginx/html

I use also docker-compose

  1. version: '3.9'
  2. services:
  3. linking-front:
  4. build: ./linkingEducationSecurity-front/
  5. ports:
  6. - "8080:80"
  7. volumes:
  8. - type: bind
  9. source: ./linkingEducationSecurity-front/src/
  10. target: /app/src

答案1

得分: 1

由于您在评论中尝试执行 RUN cd dist && ls,导致您得到了以下输出:

  1. Step 7/10 : RUN cd dist && ls ---> Running in e8f002e82f3a linking-education-security-front

步骤和 Dockerfile 部分是完美的。从构建文件夹中复制的 COPY 命令拼写错误。

请将这行代码更新为:

  1. COPY --from=build /usr/src/app/dist/linking-education-security-front /usr/share/nginx/html

尝试重新构建,这可能会起作用。

英文:

since in the comments you tried to do RUN cd dist && ls which gave you this output :

  1. Step 7/10 : RUN cd dist && ls ---> Running in e8f002e82f3a linking-education-security-front

The steps and dockerfile are perfect. the COPY command from build folder is missing its spell

update this line :

  1. COPY --from=build /usr/src/app/dist/linkingEducationSecurity-front /usr/share/nginx/html

to this :

  1. COPY --from=build /usr/src/app/dist/linking-education-security-front /usr/share/nginx/html

and try rebuilding , this might work.

huangapple
  • 本文由 发表于 2023年2月18日 07:33:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定