I am running docker-container on Amazon EC2. Currently I have added AWS Credentials to Dockerfile. Could you please let me know the best way to do this?
相关问题
- Docker task in Azure devops won't accept "$(pw
- How to generate 12 digit unique number in redshift
- Use awslogs with kubernetes 'natively'
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
Another approach is to pass the keys from the host machine to the docker container. You may add following lines to the
docker-compose
file.The best way is to use IAM Role and do not deal with credentials at all. (see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html )
Credentials could be retrieved from
http://169.254.169.254.....
Since this is a private ip address, it could be accessible only from EC2 instances.All modern AWS client libraries "knows" how to fetch, refresh and use credentials from there. So in most cases you don't even need to know about it. Just run ec2 with correct IAM role and you good to go.
As an option you can pass them at the runtime as environment variables ( i.e
docker run -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa myimage
)You can access these environment variables by running printenv at the terminal.