Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you pass multiple Docker BuildKit secrets at once?

I have a Docker image I need to build but, in order to build it, I have to use AWS credentials and configs. I've figured out how to pass a singular file as the secret; however, I can't pass multiple secret files for one run command. Is there a way that this can happen?

I pass the credentials like this: RUN --mount=type=secret,id=aws,target=/root/.aws/credentials npm run build:prepare

and I build it like this: DOCKER_BUILDKIT=1 docker build -t $IMAGE:$TAG --secret id=aws,src=$HOME/.aws/credentials .

However, I also need to pass my $HOME/.aws/config file, how can I pass this as a secret alongside my credentials file?

like image 645
BraedenK Avatar asked Oct 28 '25 22:10

BraedenK


1 Answers

I figured out a solution, although I don't know if it's the most concise way to write a docker build command with multiple secret files.

First, you have to specify in your RUN command that there are two secrets with different, unique ids and targets as such:

RUN --mount=type=secret,id=credentials,target=/root/.aws/credentials \
    --mount=type=secret,id=config,target=/root/.aws/config \
    npm run build:prepare

Then, you can pass them in like this:

DOCKER_BUILDKIT=1 docker build \
  -t $IMAGE:$TAG \
  --secret id=credentials,src=$HOME/.aws/credentials \
  --secret id=config,src=$HOME/.aws/config \
  --no-cache .
like image 75
BraedenK Avatar answered Oct 31 '25 21:10

BraedenK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!