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.)

질문됨 3년 전939회 조회
4개 답변
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
답변함 3년 전
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.

답변함 3년 전
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
답변함 3년 전
0

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

Bobik
답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인