是否有直接的方式从Docker容器中访问AWS实例元数据?
例如,在尝试获取EC2实例上的IAM角色的凭据时,这将适用于实例本身:
http://169.254.169.254/latest/meta-data/iam/security-credentials/my_role
...但不是来自在该EC2实例上运行的Docker容器中。
答案 0 :(得分:25)
在容器与主机之间执行此操作应该没有区别。容器可以直接访问EC2元数据。
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角色?
答案 1 :(得分:0)
正如@Ben Whaley在评论中提到的那样, https://docs.aws.amazon.com/AmazonECS/latest/developerguide/windows_task_IAM_roles.html
中提到的以下命令对我有用$gateway = (Get-NetRoute | Where { $_.DestinationPrefix -eq '0.0.0.0/0' } | Sort-Object RouteMetric | Select NextHop).NextHop
$ifIndex = (Get-NetAdapter -InterfaceDescription "Hyper-V Virtual Ethernet*" | Sort-Object | Select ifIndex).ifIndex
New-NetRoute -DestinationPrefix 169.254.169.254/32 -InterfaceIndex $ifIndex -NextHop $gateway