如何链接在AWS ECS任务中运行的2个容器 [英] How do I link 2 containers running in a AWS ECS task

查看:64
本文介绍了如何链接在AWS ECS任务中运行的2个容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ECS的新手,我正在尝试使用Fargate在ECS任务中部署几个容器.

我有1个正在运行的容器使用Angular2,并且在nginx上运行,另一个容器是后端,并且在Springboot上运行,并使用端口42048.

我将awsvpc网络与Fargate一起使用,我必须这样做.

Angular应用使用localhost:42048/some_url与后端进行通信,并且在我的本地docker中可以正常工作,但是在AWS中,前端找不到后端.目前,我的端口映射为80的前端和42048的后端,而在本地部署时前端能够以localhost:42048的方式找到后端

任何帮助将不胜感激.谢谢

解决方案

AWSVPC中不允许链接.

当设置为网桥时,您只能在网络模式下进行链接.

 链接类型:字符串数组必填:否 

link参数允许容器相互通信无需端口映射.仅在网络中受支持任务定义的模式设置为桥接.名称:internalName结构类似于Docker链接中的name:alias.最多255字母(大写和小写),数字,连字符和下划线被允许.有关链接Docker容器的更多信息,请转到至然后在前端容器中提到后端容器的名称.

I am new to ECS and I am trying to deploy a couple of containers in a ECS task using Fargate.

I have 1 container running that uses Angular2 and is running on nginx, the other container is the backend and is running on Springboot and uses the port 42048.

I am using the awsvpc network with Fargate and I have to do it that way.

The Angular app communicates with the backend using localhost:42048/some_url and it works fine in my local docker but in AWS the front-end doesn't find the backend. Currently I have my ports mapped with 80 for the front end and 42048 for the backend and the front-end when deployed locally was able to find the backend as localhost:42048

Any help would be appreciated. Thank you

解决方案

linking is not allowed in AWSVPC.

You can do linking only in network mode when its set to bridge.

links

Type: string array

Required: no

The link parameter allows containers to communicate with each other without the need for port mappings. Only supported if the network mode of a task definition is set to bridge. The name:internalName construct is analogous to name:alias in Docker links. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. For more information about linking Docker containers, go to https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/. This parameter maps to Links in the Create a container section of the Docker Remote API and the --link option to docker run.

Note

This parameter is not supported for Windows containers or tasks using the awsvpc network mode.

Important

Containers that are collocated on a single container instance may be able to communicate with each other without requiring links or host port mappings. Network isolation is achieved on the container instance using security groups and VPC settings.

task_definition_parameters

In network mode, you have to define two containers in the same task definition and then mentioned the name of the container in the link.

And then Mentioned the name of backend container in frontend container.

这篇关于如何链接在AWS ECS任务中运行的2个容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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