从 Docker 容器中获取 AWS 实例元数据? [英] Fetching AWS instance metadata from within Docker container?
问题描述
是否有一种直接的方法可以从 Docker 容器中访问 AWS 实例元数据?
Is there a straightforward way to access AWS instance metadata from within a Docker container?
例如,当尝试为 EC2 实例上的 IAM 角色获取凭证时,这将适用于实例本身:
For example, when trying to fetch credentials for an IAM role on an EC2 instance, this would work on the instance itself:
http://169.254.169.254/latest/meta-data/iam/security-credentials/my_role
...但不是来自在该 EC2 实例上运行的 Docker 容器内.
...but not from within a Docker container running on that EC2 instance.
推荐答案
在容器中执行此操作与在主机中执行此操作应该没有区别.容器可以直接访问 EC2 元数据.
There should be no difference between doing this in a container vs the host. The container can access EC2 metadata directly.
root@f1e5964e87e4:/# curl http://169.254.169.254/latest/meta-data/iam/security-credentials/myrole
{
"Code" : "Success",
"LastUpdated" : "2014-03-14T17:07:24Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "mykey",
"SecretAccessKey" : "mysecret",
"Token" : "mytoken",
"Expiration" : "2014-03-14T23:09:39Z"
}
当您在容器内尝试命令时,您看到了什么?是否分配了 IAM 角色?
What do you see when you try the command from within the container? has an IAM role assigned?
这篇关于从 Docker 容器中获取 AWS 实例元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!