I have two multistage dockerfile's for building two containers (amongst several). One works perfectly, the other fails in the COPY --from-prodmods
stage with an error message
failed to compute cache key: "/from=prodmods" not found: not found
Here are the two docker files:-
The one that works:
FROM node:lts-alpine3.18 AS libraries
WORKDIR /app
COPY client-package.json package.json
COPY scripts/buildlibs.js scripts/
RUN --mount=type=cache,target=~.npm npm install && npm run buildlibs
COPY service-worker.js .
COPY scripts/swupdate.js scripts/update.js scripts/
COPY version.inc .
RUN --mount=type=cache,target=~.npm npm run swupdate
FROM nginx:1.25-alpine3.18-slim AS client
RUN mkdir -p /usr/share/pas/videos
COPY nginxconf/default.conf /etc/nginx/conf.d/
WORKDIR /usr/share/nginx/html
COPY client ./
COPY --from=libraries /app/libs ./libs
COPY --from=libraries /app/service-worker.js ./
and the one that doesn't
FROM node:lts-alpine3.18 AS prodmods
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=~.npm npm ci --omit=dev
COPY scripts/makecontrol.js scripts/
RUN --mount=type=secret,id=token,target=./token node scripts/makecontrol.js
FROM node:lts-alpine3.18 AS server
#LABEL com.hartley-consultants.maintainer="Alan Chandler <alan.chandler@hartley-consultants.com>"
WORKDIR /app
COPY from=prodmods /app/node_modules ./
COPY from=prodmods /app/secret/token ./
RUN mkdir -p pfiles
COPY server ./
COPY version.inc .
##
## Allows for coloured output (https://stackoverflow.com/questions/33493456/docker-bash-prompt-does-not-display-color-output)
ENV TERM xterm-256color
CMD npm run
I have been trying to get this to work for the best part 3 days. I've googled every thing I can about this. But I can't find an answer.
What is wrong with the second file that means it fails?
You have a typo. You have to use '--from' instead of 'from'. Change COPY from=prodmods /app/node_modules ./
to COPY --from=prodmods /app/node_modules ./