No such file or directory when accessing secret files in Docker build

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

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

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 .

HI Ian,

Thanks for reaching out.

That all looks correct, the only small issue I see is the ID shouldn’t have a ., as noted on the docs.

If your filename contains non-alphanumeric characters, replace them with _ for the id= part.

That doesn’t feel like it would cause that particular error, but it may be something to rule out first?

Kind regards


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.