阅读背景:

从Docker容器中获取AWS实例元数据?

来源:互联网 

Is there a straightforward way to access AWS instance metadata from within a Docker container?

是否有直接的方法从Docker容器中访问AWS实例元数据?

For example, when trying to fetch credentials for an IAM role on an EC2 instance, this would work on the instance itself:

例如,在尝试获取EC2实例上的IAM角色的凭据时,这将适用于实例本身:

https://169.254.169.254/latest/meta-data/iam/security-credentials/my_role

...but not from within a Docker container running on that EC2 instance.

...但不是在该EC2实例上运行的Docker容器中。

1 个解决方案

#1


22  

There should be no difference between doing this in a container vs the host. The container can access EC2 metadata directly.

在容器和主机之间执行此操作应该没有区别。容器可以直接访问EC2元数据。

root@f1e5964e87e4:/# curl https://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"
}

What do you see when you try the command from within the container? has an IAM role assigned?

当您从容器中尝试命令时,您看到了什么?是否分配了IAM角色?


分享到: