带有nginx的ElasticBeanstalk MultiContainer docker

时间:2017-02-23 05:29:07

标签: nginx docker elastic-beanstalk

我有两个处理不同但相关功能的应用程序。我想将它们作为单个实体部署在单个主机上:port。

我的计划是使用elasticbeanstalk的多容器泊坞平台。每个应用程序都是一个容器。

如何将它们绑在一起?是否可以在eb主机上安装和配置nginx?

1 个答案:

答案 0 :(得分:0)

您需要在Dockerrun.aws.json中定义构成应用程序的所有容器(以及nginx容器)。

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "nginx-proxy-conf",
      "host": {
        "sourcePath": "/var/app/current/conf.d"
      }
    }  
  ],
  "containerDefinitions": [
    {
      "name": "first-app",
      "image": "FIRST_APP_IMAGE_NAME:FIRST_APP_TAG",
      "environment": [],
      "essential": true,
      "memoryReservation": 200,
      "mountPoints": [],
      "portMappings": [
        {
          "hostPort": 8081,
          "containerPort": 8080
        }
      ]
    },
    {
      "name": "secondapp",
      "image": "SECOND_APP_IMAGE_NAME:SECOND_APP_TAG",
      "environment": [],
      "essential": true,
      "memoryReservation": 200,
      "mountPoints": [],
      "portMappings": [
        {
          "hostPort": 8082,
          "containerPort": 8080
        }
      ]
    }
    {
      "name": "nginx-proxy",
      "image": "nginx",
      "essential": true,
      "memoryReservation": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "firstapp", "secondapp"
      ],
      "mountPoints": [
        {
          "sourceVolume": "nginx-proxy-conf",
          "containerPath": "/etc/nginx/conf.d",
          "readOnly": true
        }
      ]
    }
  ]
}

现在,当我们将app容器链接到nginx容器时,我们可以使用它们的名称作为主机名来引用它们。

然后你需要将Dockerrun.aws.json与nginx config conf.d/default.conf文件(放入conf.d文件夹)一起压缩,你需要在其中指定

location /firstapp/ {
    proxy_pass http://firstapp;
}

location /secondapp/ {
    proxy_pass http://secondapp;
}

请在php应用程序之前参考nginx代理的AWS示例。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html