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?
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 .