Docker与awsvpc网络模式链接 [英] Docker links with awsvpc network mode

查看:126
本文介绍了Docker与awsvpc网络模式链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用tomcat:8.5-jre8-alpine映像在ECS中部署的Java Webapp。该任务的网络模式为awsvpc;我有许多任务在3个EC2实例(由ALB开头)上运行。

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.

这工作正常,但现在我想在每个实例前面添加nginx反向代理tomcat容器,类似于此示例: https:// github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy

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

当我尝试保存新任务定义时,收到了错误:当网络类型为awsvpc时不支持链接

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

我正在使用awsvpc网络模式,因为它使我可以通过安全组精细控制入站流量。

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

使用awsvpc网络模式时,是否可以用两个链接的容器创建任务定义?

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

推荐答案

您根本不需要链接部分,因为awsvpc允许您简单地通过使用

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


localhost:8080(或其他容器映射到的任何端口)

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

i n您的nginx配置文件中。

in your nginx config file.

因此从json中删除链接,并在nginx配置中使用localhost:{container-port}。就这么简单。

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

这篇关于Docker与awsvpc网络模式链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆