无法解决:无法计算缓存键:无法计算 ref 的校验和。 。 。 “/app/build”:未找到

问题描述 投票:0回答:1

我试图通过运行

docker compose up
来对项目进行 dockerize,但显示了此错误。

这是 Dockerfile

FROM node:gallium-alpine3.18 as build
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm install
COPY . .
RUN npm run install-all

# Stage 2
FROM nginx
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
RUN echo ${PWD} && ls -la
COPY --from=build /app/build .
ENTRYPOINT ["nginx", "-g", "daemon off;"]

这是

docker-compose.yml

version: '3.8'

services:
  app: 
    container_name: product_container
    image: product_image
    build:
      context: .
    ports:
      - 8000:8000

以下是可通过

npm run

获得的脚本
install-all
    cd server && npm i && cd .. && cd client && npm i
  server
    cd server && npm start
  server-dev
    cd server && npm run dev
  client-dev
    cd client && vite
  client-build
    cd client && vite build
  client-preview
    cd client && vite preview

我什至尝试将

COPY --from=build /app/build .
更改为
COPY --from=build /app/install-all
以防万一,但我遇到了同样的错误。

错误:

[+] Running 1/1
 ! app Warning                                                                                                                                                   4.6s 
[+] Building 15.2s (19/19) FINISHED
 => [app internal] load build definition from Dockerfile                                                                                                         0.0s
 => => transferring dockerfile: 376B                                                                                                                             0.0s
 => [app internal] load .dockerignore                                                                                                                            0.0s
 => => transferring context: 58B                                                                                                                                 0.0s
 => [app internal] load metadata for docker.io/library/nginx:latest                                                                                              3.3s
 => [app internal] load metadata for docker.io/library/node:gallium-alpine3.18                                                                                   2.5s
 => [app auth] library/node:pull token for registry-1.docker.io                                                                                                  0.0s
 => [app auth] library/nginx:pull token for registry-1.docker.io                                                                                                 0.0s
 => [app build 1/7] FROM docker.io/library/node:gallium-alpine3.18@sha256:bca38851a77922e849907c57588bdf3dfcf95725186d7c26cdfd64da730989d3                       0.0s
 => [app internal] load build context                                                                                                                           10.8s
 => => transferring context: 6.56MB                                                                                                                             10.3s
 => [app stage-1 1/5] FROM docker.io/library/nginx@sha256:af296b188c7b7df99ba960ca614439c99cb7cf252ed7bbc23e90cfda59092305                                       0.0s
 => CACHED [app stage-1 2/5] WORKDIR /usr/share/nginx/html                                                                                                       0.0s
 => CACHED [app stage-1 3/5] RUN rm -rf ./*                                                                                                                      0.0s
 => CACHED [app stage-1 4/5] RUN echo ${PWD} && ls -la                                                                                                           0.0s
 => CACHED [app build 2/7] WORKDIR /app                                                                                                                          0.0s
 => CACHED [app build 3/7] COPY package.json .                                                                                                                   0.0s
 => CACHED [app build 4/7] COPY package-lock.json .                                                                                                              0.0s 
 => CACHED [app build 5/7] RUN npm install                                                                                                                       0.0s 
 => CACHED [app build 6/7] COPY . .                                                                                                                              0.0s 
 => CACHED [app build 7/7] RUN npm run install-all                                                                                                               0.0s 
 => ERROR [app stage-1 5/5] COPY --from=build /app/build .                                                                                                       0.0s 
------
 > [app stage-1 5/5] COPY --from=build /app/build .:
------
failed to solve: failed to compute cache key: failed to calculate checksum of ref a02f4bce-0632-4ac7-b1fc-91d8f44501e2::vctjyp0apfdei1qda0qpul22h: "/app/build": not found
docker docker-compose dockerfile npm-scripts
1个回答
0
投票

确保

.dockerignore
不包含
/app/build

© www.soinside.com 2019 - 2024. All rights reserved.