简体   繁体   中英

ElasticBeanstalk MultiContainer docker with nginx

I have two applications that handle different, but related functionality. I would like to deploy them as a single entity on a single host:port.

My plan is to use elasticbeanstalk's multicontainer docker platform. Each application would be a container.

How can I tie them together? Is it possible to install and configure nginx on the eb host?

You need to define all containers that comprise your application (together with nginx container) in Dockerrun.aws.json .

{
  "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
        }
      ]
    }
  ]
}

Now as we linked app containers to nginx container we can refer to them using their names as hostnames.

And then you need to deploy Dockerrun.aws.json zipped together with nginx config conf.d/default.conf file (put into conf.d folder) in which you need to specify

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

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

Please also refer to AWS example of nginx proxy before php application. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM