Search code examples
amazon-web-servicesamazon-ec2docker

'aws configure' in docker container will not use environment variables or config files


So I have a docker container running jenkins and an EC2 registry on AWS. I would like to have jenkins push containers back to the EC2 registry.

To do this, I would like to be able to automate the aws configure and get login steps on container startup. I figured that I would be able to

export AWS_ACCESS_KEY_ID=*
export AWS_SECRET_ACCESS_KEY=*
export AWS_DEFAULT_REGION=us-east-1
export AWS_DEFAULT_OUTPUT=json

Which I expected to cause aws configure to complete automatically, but that did not work. I then tried creating configs as per the AWS docs and repeating the process, which also did not work. I then tried using aws configure set also with no luck.

I'm going bonkers here, what am I doing wrong?


Solution

  • No real need to issue aws configure instead as long as you populate env vars

    export AWS_ACCESS_KEY_ID=aaaa
    export AWS_SECRET_ACCESS_KEY=bbbb
    ... also export zone and region
    

    then issue

    aws ecr get-login --region ${AWS_REGION}
    

    you will achieve the same desired aws login status ... as far as troubleshooting I suggest you remote login into your running container instance using

    docker exec -ti CONTAINER_ID_HERE  bash
    

    then manually issue above aws related commands interactively to confirm they run OK before putting same into your Dockerfile