How to access container from another container

0

Hello,
I have multi container setup - app and database:

"containers": {
"database": {
"image": "bitnami/mariadb:10.5",
"command": [],
}
},
"web": {
"image": ":my-service.web.7",
"command": [],
"ports": {
"80": "HTTP"
}
}
},

What hostname should web container call to access database?

In Docker Compose there is default stack network with DNS where I can call it by its service name (container name in Lightsail) - database:3306, but this does not work in Lightsail.

I know I can call it from outside by "private domain" - my-service.service.local:3306 with 3306 port specified, but I does not want to expose database to another AWS resources.

(I know there is no persistance for database, not an issue there.)

asked 2 years ago845 views
4 Answers
0

Hello,

In this case, you'd need to make sure port 3306 is exposed on the database container (similar to how port 80 is exposed on your web container). Then, you would be able to access the database container from the web container via localhost:3306.

Unfortunately, there's not a way to stop this from exposing other Lightsail resources from accessing this via private domain (ie, via my-service.service.local:3306). You'd need to update the database container to not accept traffic from outside of localhost. I'll mention that if you have VPC Peering disabled on the Lightsail console, only your other Lightsail resources would have access to it; your resources from other AWS services wouldn't be able to access it.

Additionally, in case you are not aware: if you're running this service with a scale greater than 1, each node will have both containers and will be running independently of the others. This means you'd have multiple databases (one per node) and each node would only communicate with its own database.

Thank you for using Amazon Lightsail!
-Maxwell

Maxwell
answered 2 years ago
0

Thank you for reply.

It is very confusing that Lightsail does not work like usual Docker PaaS. Would be nice to clarify this in docs. :-)

Also thank you for note about scaling. This reminds me similar issue I faced: How to communicate with another containers on another nodes? I need it for Memcached, so app can invalidate cache on all instances, not only its. I am not locked to Memcached, I can also use Redis, if Lightsail has this synchronisation solved somehow.

answered 2 years ago
0

Thank you for your feedback about our docs. I'll forward this along to the team.

I don't believe there's a way to communicate between containers on different nodes. The way to achieve what you want would be to create separate container services with memcache/redis, or create Lightsail instances with memcache/redis, then refer to them on your web container by their private endpoints. Lightsail instances might make more sense since the storage is not ephemeral.

Thank you for sharing your use case. We're constantly looking for ways to improve our service, and feedback like this is always useful for us.

Best,
Maxwell

Maxwell
answered 2 years ago
0

Strange. Does it mean that official Redis template results in an inconsistent cluster when scaled up?

Bobik
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions