I tried copying a secret file during a Docker build as explained in the docs, but the build failed with the following error:
cp: cannot stat "/etc/secrets/google_credentials.json': No such file or directory
This is a simplified version of my Dockerfile:
# syntax = docker/dockerfile:1.2 FROM node:16 as build WORKDIR /app COPY .yarn .yarn/ COPY package.json yarn.lock .yarnrc.yml ./ COPY backend/package.json backend/ RUN yarn workspaces focus backend COPY backend backend/ RUN --mount=type=secret,id=google_credentials.json,dst=/etc/secrets/google_credentials.json cp /etc/secrets/google_credentials.json backend/ RUN yarn be build EXPOSE 3000 CMD yarn be dist
And here’s a screenshot from the build logs:
It builds just fine on my local machine when running
docker buildx build --secret id=google_credentials.json,src=backend/google_credentials.json .