16

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.

Robert
  • 33,429
  • 8
  • 90
  • 94
user846445
  • 221
  • 1
  • 3
  • 14

1 Answers1

41

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> ...
Qasim Sarfraz
  • 5,822
  • 2
  • 20
  • 26
  • `${USERPROFILE}` or `$env:USERPROFILE` for those using windows as a host. Is there any way to do this using a dockerfile (not docker-compose file) – Ash Dec 05 '22 at 08:49