我一直在环顾四周,并且在使用多容器Docker环境在Amazon Elastic Beanstalk上设置HTTPS / SSL时,没有找到关于最佳实践的太多内容。
关于单容器配置,有很多东西,但是对于多容器,则没有。
我的Dockerrun.aws.json看起来像这样:
{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "app-frontend",
"host": {
"sourcePath": "/var/app/current/app-frontend"
}
},
{
"name": "app-backend",
"host": {
"sourcePath": "/var/app/current/app-backend"
}
}
],
"containerDefinitions": [
{
"name": "app-backend",
"image": "xxxxx/app-backend",
"memory": 512,
"mountPoints": [
{
"containerPath": "/app/app-backend",
"sourceVolume": "app-backend"
}
],
"portMappings": [
{
"containerPort": 4000,
"hostPort": 4000
}
],
"environment": [
{
"name": "PORT",
"value": "4000"
},
{
"name": "MIX_ENV",
"value": "dev"
},
{
"name": "PG_PASSWORD",
"value": "xxxx"
},
{
"name": "PG_USERNAME",
"value": "xx"
},
{
"name": "PG_HOST",
"value": "xxxxx"
}
]
},
{
"name": "app-frontend",
"image": "xxxxxxx/app-frontend",
"memory": 512,
"links": [
"app-backend"
],
"command": [
"npm",
"run",
"production"
],
"mountPoints": [
{
"containerPath": "/app/app-frontend",
"sourceVolume": "app-frontend"
}
],
"portMappings": [
{
"containerPort": 3000,
"hostPort": 80
}
],
"environment": [
{
"name": "REDIS_HOST",
"value": "xxxxxx"
}
]
}
],
"family": ""
}
到目前为止,我的想法是我需要将nginx容器引入混合以代理这两个服务并处理诸如将不同的域名映射到不同的服务之类的事情。
我会采用通常的方法,即只设置nginx并正常配置SSL,还是有更好的方法,就像我使用.ebextensions方法(http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-singleinstance-docker.html)针对单个容器看到的那样?
最佳答案
这更多是一个主意(我实际上还没有做到这一点,也不知道它是否会起作用)。但是这些组件似乎都可用于创建ALB,该ALB可以根据路径规则将流量定向到一个或另一个进程。
这是我在想根据http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html可用的选项通过.ebextensions
配置文件来完成的工作:
aws:elasticbeanstalk:environment:process:default
确保默认的应用程序端口和运行状况检查已按照您的意愿进行设置(在这种情况下,假设端口80是您的默认设置。aws:elasticbeanstalk:environment:process:process_name
创建转到您的第二个服务(在本例中为端口4000)的backend
进程。 aws:elbv2:listenerrule:backend
为您的后端创建规则,该规则将使用/backend/*
之类的路径。 aws:elbv2:listener:443
(例如http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-applicationloadbalancer.html)创建SSL侦听器。 我不确定是否需要为
aws:elbv2:listener:default
的默认侦听器创建其他规则。似乎默认值可能只匹配/*
,因此在这种情况下,发送到/backend/*
的所有内容都将到达端口4000容器,而其他任何内容都将到达端口3000容器。
关于amazon-web-services - Elastic Beanstalk上的HTTPS(Docker多容器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985809/