3
votes

I have a Java webapp deployed in ECS using the tomcat:8.5-jre8-alpine image. The network mode for this task is awsvpc; I have many of these tasks running across 3 EC2 instances fronted by an ALB.

This is working fine but now I want to add an nginx reverse-proxy in front of each tomcat container, similar to this example: https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy.

My abbreviated container definition file is:

{
    "containerDefinitions": [
     {
       "name": "nginx",
       "image": "<NGINX reverse proxy image URL>",
       "memory": "256",
       "cpu": "256",
       "essential": true,
       "portMappings": [
         {
           "containerPort": "80",
           "protocol": "tcp"
         }
       ],
       "links": [
         "app"
       ]
     },
     {
       "name": "app",
       "image": "<app image URL>",
       "memory": "1024",
       "cpu": "1024",
       "essential": true
     }
    ],
    "volumes": [],
    "networkMode": "awsvpc",
    "placementConstraints": [],
    "family": "application-stack"
}

When I try to save a new task definition I received the error: "links are not supported when the network type is awsvpc"

I am using the awsvpc network mode because it gives me granular control over the inbound traffic via a security group.

Is there any way to create a task definition with 2 linked containers when using awsvpc network mode?

2

2 Answers

8
votes

You dont need the linking part at all, because awsvpc allows you to reference other containers simply by using

localhost:8080 (or whatever port is your other container mapped to)

in your nginx config file.

So remove links from your json and use localhost:{container-port} in nginx config. Simple as that.

0
votes

Actually if you want to use a reverse-proxy you can stop using links, because you can make service discovery or using your reverse-proxy to use your dependency.

If you still want to use link instead of using that reverse proxy you can use consul and Fabio. Both services are dockerizable.

With this, there is no necessity to use awsvpc and you can use consul for service-discovery.

Hope it helps!