Search code examples
dockeraws-clidocker-build

New Docker Build secret information for use with aws cli


I would like to use the new --secret flag in order to retreive something from aws with its cli during the build process.

# syntax = docker/dockerfile:1.0-experimental
FROM alpine
RUN --mount=type=secret,id=mysecret,dst=/root/.aws cat /root/.aws

I can see the credentials when running the following command:

docker build --no-cache --progress=plain --secret id=mysecret,src=%USERPROFILE%/.aws/credentials .

However, if I adjust the command to be run, the aws cli cannot find the credentials file and asks me to do aws configure:

RUN --mount=type=secret,id=mysecret,dst=/root/.aws aws ssm get-parameter

Any ideas?


Solution

  • The following works:

    # syntax = docker/dockerfile:1.0-experimental
    FROM alpine
    RUN --mount=type=secret,id=aws,dst=/aws export AWS_SHARED_CREDENTIALS_FILE=/aws aws ssm get-parameter ...