Passing aws credentials to Docker

user846445 picture user846445 · Nov 23, 2018 · Viewed 7.8k times · Source

I have a docker container golang code which interacts with aws resources. In the testing environment, we use iam role. But How do I test locally. How to use aws credentials to run my docker locally.I am using docker file to build the docker image.

Answer

Qasim Sarfraz picture Qasim Sarfraz · Nov 23, 2018

Just mount your credential directory as read-only using:

docker run -v ${HOME}/.aws/credentials:/root/.aws/credentials:ro  ...

given you have root as the user in the container and also have setup the host using this guide for credentials file.

or pass them directly using environment variables as:

docker run -e AWS_ACCESS_KEY_ID=<ACCESS_KEY> -e AWS_SECRET_ACCESS_KEY=<SECRET_KEY> ...