Caching of secrets not wanted

I’m building docker images via a build script, all local (docker.chandlerfamily.org.uk) is a repository on a local Synology NAS.

node scripts/buildlibs.js
node scripts/builddockerenv.js home

docker buildx build --push -f Dockerfile-client -t docker.chandlerfamily.org.uk/client .
docker buildx build --push -f Dockerfile-server -t docker.chandlerfamily.org.uk/server .
docker buildx build --push -f Dockerfile-timer -t docker.chandlerfamily.org.uk/timer .
docker buildx build --push -f Dockerfile-mail --secret id=pfcred,src=pfcred/relay_password -t docker.chandlerfamily.org.uk/mail .

The key issue is the secret passed to docker.chandlerfamily.org.uk/mail

Inside Dockerfile-mail I do the following

FROM alpine:latest AS relay-builder
RUN --mount=type=cache,target=/var/cache/apk apk add postfix 
WORKDIR /etc/postfix
RUN --mount=type=secret,id=pfcred,target=/etc/postfix/relay_password,required postmap relay_password 

and further down the same file after another “FROM” do

COPY --from=relay-builder /etc/postfix/relay_password.lmdb .

I bring the resultant image up via docker compose up -d
and then enter the container

docker exec -it pasmail sh

ive also installed lmdb-tools inside the container and can therefore dump relay_password.lmdb out as ascii text

It shows a version of the original relay_password several interations ago, in particular with the wrong password.

I assume that either secret is getting cached somewhere or the result is being cached. How do I stop it doing this?

Is everything happening on the same machine? Are you sure you run the latest image?

Apart from the repository I am using everything else is on the same machine which is Debian Stable. The docker engine running there is 26.0.1

I can prevent the problem by building with the --no-cache flag but its a lot slower that way.

docker buildx build --no-cache --push -f Dockerfile-mail --secret id=pfcred,src=pfcred/relay_password -t docker.chandlerfamily.org.uk/mail .

My guess is a change in the secret is not triggering the line

RUN --mount=type=secret,id=pfcred,target=/etc/postfix/relay_password,required postmap relay_password 

to run again.

1 Like