简体   繁体   English

AWS ECS 中的服务发现

[英]Service discovery within AWS ECS

I currently have a Redis, Postgres and a few Golang containers in a project of mine.我目前在我的一个项目中有一个 Redis、Postgres 和一些 Golang 容器。 I've got it all working locally on my machine using docker-compose.我已经使用 docker-compose 在我的机器上本地工作了。

  redis:
    container_name: redis
    build:
      context: .
      dockerfile: redis/Dockerfile
    ports:
      - 6379:6379
    networks:
      - my-network

This allows me in my Golang microservice to use the container name to connect to the Redis container:这允许我在我的 Golang 微服务中使用容器名称连接到 Redis 容器:

&redis.Pool{
    Dial: func() (redis.Conn, error) {
        return redis.Dial("tcp", "redis:6379")
},

This all works perfectly, however, I want to place these containers within ECR and use ECS.这一切都很完美,但是,我想将这些容器放在 ECR 中并使用 ECS。 I'm a bit confused as to how to identify my services and communicate with them in AWS.我对如何识别我的服务并在 AWS 中与它们进行通信有点困惑。 If I set the namespace to say example and then the service discovery name to redis_service within the ECS service is it as simple as using:如果我将命名空间设置为example ,然后在 ECS 服务中将服务发现名称设置为redis_service ,那么它就像使用一样简单:

&redis.Pool{
    Dial: func() (redis.Conn, error) {
        return redis.Dial("tcp", "example.redis_service:6379")
},

Any help would be appreciated!任何帮助,将不胜感激!

After linking your containers you will be able to create connection between them the same way like it is done when setting it with docker-compose.链接容器后,您将能够在它们之间创建连接,就像使用 docker-compose 设置时一样。 It is described in AWS documentation for Dockerrun.aws.json v2它在Dockerrun.aws.json v2的 AWS 文档中进行了描述

links List of containers to link to. links要链接到的容器列表。 Linked containers can discover each other and communicate securely.链接的容器可以相互发现并安全通信。

That is if you are using Multicontainer Docker.也就是说,如果您使用的是多容器 Docker。

For more advanced/manual usage of ECS you may also be interested in this blog post有关 ECS 的更高级/手动使用,您可能还对这篇 文感兴趣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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