【发布时间】:2015-12-24 04:08:58
【问题描述】:
我有一个打算在 ElasticBeanstalk 环境中运行的 Docker 多容器配置。
EB 环境在公共子网中的 VPC 中运行,具有单个负载均衡器和单个实例绑定。
看起来所有容器都运行良好,但即使我将它们定义为链接容器,它们也无法相互通信。
我需要怎么做才能让所有这些容器相互通信?
我的 Dockerrun.aws.json 看起来像这样:
"containerDefinitions":
[
{
"name": "proxy",
"image": "nginx",
"essential": true,
"memory": 128,
"portMappings":
[
{
"hostPort": 80,
"containerPort": 80
}
],
"links":
[
"webapp"
],
"mountPoints":
[
{
"sourceVolume": "nginx-conf",
"containerPath": "/etc/nginx/conf.d",
"readOnly": true
},
{
"sourceVolume": "awseb-logs-proxy",
"containerPath": "/var/log/nginx"
}
]
},
{
"name": "webapp",
"image": "jetty",
"memory": 2048,
"essential": true,
"portMappings":
[
{
"hostPort": 8080,
"containerPort": 8080
}
],
"links":
[
"mongodb"
],
"mountPoints":
[
{
"sourceVolume": "jetty-webapp",
"containerPath": "/var/lib/jetty/webapps",
"readOnly": false
},
{
"sourceVolume": "awseb-logs-webapp",
"containerPath": "/var/log/jetty"
}
]
},
{
"name": "mongodb",
"image": "mongo",
"memory": 1024,
"essential": true,
"portMappings":
[
{
"hostPort": 27017,
"containerPort": 27017
}
],
"mountPoints":
[
{
"sourceVolume": "mongodb-data",
"containerPath": "/data/db",
"readOnly": false
}
]
}
]
【问题讨论】:
-
检查您的安全组。您可能需要打开一些端口。通常,这就是我的 EB 无法与外界通信的原因。
-
似乎我可以访问 Nginx,但无法连接到上游服务器。在 WAR 中,我看到它无法连接到 Mongo。由于 Jetty 和 Mongo 在同一实例上运行在 Nginx 后面,我还需要在安全组上打开 80 以上的端口吗?
-
作为注释,我有这些 SG:-vpc:默认 VPC 安全组(所有流量)-net:特殊安全组 (80/22)-dev-vpc:EB 安全组 (80/22 ) - dv-lb: EB 负载均衡器组 (80)
-
通常,您必须将每个安全组添加到传入流量列表中,以便它们可以相互通信。另外,如果你有一个 DB,你需要在 SG 中启用 DB 端口。
标签: amazon-web-services docker amazon-elastic-beanstalk