Emre Bayram
Emre Bayram

Reputation: 148

How can I expose docker containers internally to each other with AWS CloudFormation?

I am an AWS noob. I have a web server container and a selenium hub container. My web server needs to access the other container; I can do this on development environment using docker-compose (by default containers are exposed to each other by name). I am confused about how to do this by using AWS CloudFormation. There is "links" parameter in the ContainerDefinition but I think this uses the legacy docker link parameter. So I am reluctant to use it.

Any recommendation?

P.S: I don't want to open the selenium instance to public so using public hostnames/IPs is not an option.

Upvotes: 1

Views: 411

Answers (3)

lexicore
lexicore

Reputation: 43671

Create a private DNS namespace and register your services in this namespace via DnsConfig. This will make your service addressable via domain name provided as Name. We use Type: A, TTL: 10 as DnsRecords configuration.

Upvotes: 0

Emre Bayram
Emre Bayram

Reputation: 148

Ok I solved my problem. I followed this blog.

and placed 2 tightly coupled containers into the same task definition and i was just able to access the other container like : localhost:port.

It is working fine.

For others who face the same problem; this solution may not be the best for you if your containers are not tightly coupled and one day you may need to deploy them in separate machines.

But for me it is good.

Upvotes: 2

trallnag
trallnag

Reputation: 2376

While the links parameter is legacy in the pure Docker world, it is still the easiest way to connect containers in the AWS ECS world without relying on dedicated service discovery (for example Consul or Route 53).

The biggest caveat with using links is that circular links are not possible. In addition, the containers must run in the same task / service. The links parameter will not work across multiple tasks / services.

Upvotes: 2

Related Questions