COPY cmd in multi stage build fails

Hi, can somebody help me? Already google a lot and tried a lot but it just doesn’t work.
I have this multistage build and when I try to copy my build files in the last stage, the copy cmd always fails with:

failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount2911345790/home/node/app/app: lstat /var/lib/docker/tmp/buildkit-mount2911345790/home/node/app/app: no such file or directory

Here is my docker file:

# DockerFile for production environment


FROM node:18-slim as ts-compiler
ARG PORT
ARG WORK_DIR=/home/node/app
RUN apt-get update
RUN apt-get install -y openssl
RUN npm i -g npm@9.0.1
WORKDIR ${WORK_DIR}
RUN mkdir -p ${WORK_DIR}/src/submodules/common-db
COPY . .
RUN npm install
RUN npm run submodules:install
WORKDIR ${WORK_DIR}/src/submodules/common-db

RUN node_modules/prisma/build/index.js generate


WORKDIR ${WORK_DIR}
RUN npm run build


FROM node:18-slim as ts-remover
ARG PORT
ARG WORK_DIR=/home/node/app
RUN npm i -g npm@9.0.1
COPY --from=ts-compiler ${WORK_DIR}/package*.json ./
COPY --from=ts-compiler ${WORK_DIR}/lib ./
COPY --from=ts-compiler ${WORK_DIR}/jwt-prod.key ./

RUN npm ci 

FROM gcr.io/distroless/nodejs18-debian11
ARG PORT
ARG WORK_DIR=/home/node/app
WORKDIR ${WORKDIR}
COPY --from=ts-remover ${WORK_DIR}/app/lib /home/node/app/lib
COPY --from=ts-remover ${WORK_DIR}/app/jwt-prod.key /home/node/app/jwt-prod.key
COPY --from=ts-remover ${WORK_DIR}/app/package.json /home/node/app/package.json
EXPOSE ${PORT}
USER 1000
ENTRYPOINT [ "node", "./lib/index.js" ]

Any help is highly appreciated!
Thank you

Are you sure the path /home/node/app/app exists in the ts-remover stage? According the error message it does not. It looks like an app to many in either your “WORK_DIR” ARG or in the COPY instructions. You need to remove it either in the “WORK_DIR” ARG or in the COPY instructions.

thank you for your reply.
Yes I found that but even with correct paths it doesn’t work, here is my last try:


FROM node:18-slim as ts-remover

WORKDIR /home/node/app

RUN npm i -g npm@9.0.1

COPY --from=ts-compiler /home/node/app/package*.json ./

COPY --from=ts-compiler /home/node/app/lib ./

COPY --from=ts-compiler /home/node/app/jwt-prod.key ./

RUN npm ci

# FROM gcr.io/distroless/nodejs18-debian11

# ARG PORT

# ARG WORK_DIR=/home/node/

# WORKDIR /home/node/app

# COPY --from=ts-remover /home/node/app/lib /.

# COPY --from=ts-remover /home/node/app/jwt-prod.key /home/node/app/jwt-prod.key

# COPY --from=ts-remover /home/node/app/package.json /home/node/app/package.json

# EXPOSE ${PORT}

# USER 1000

ENTRYPOINT [ "node", "./lib/index.js" ]

I try now to remove the third stage and inspect wether all those things exits in the second stage

Please format your post properly, as it’s hard to read the way it is now.

Sorry will do.
I solved it. My copy cmd from stage 1 to 2 wasn’t correct.
Thank you for replies and help