Communicating with different services within your project #
Very often our applications are not standalone and require communicating with other services in order to perform operations correctly.
In this guide you’ll find the most important aspects to be able to configure this kind of applications, based on the sample storage app available on this Gitlab repository.
The sample is a simple Go application that provides data storage functionality through HTTP requests. It uses two external services: MySQL for persistence and and valkey as a temporary cache.
Exposing services #
In order to access these services the compose specification requires at least one ports
entry that specifies the corresponding service-port:container-port
value.
For example, in the case of the cache
service, port 6379 in the container is published as a service on the same port:
services:
cache:
image: valkey/valkey
ports:
- 6379:6379
[...]
Something similar can be observed for the db
service:
db:
image: mysql
ports:
- 3306:3306
Without defining ports
, levv won’t recognize your service as accessible.
Accessing exposed services #
When you create a service exposing ports, it is possible to access it from any other application using its name, only within the same project. No FQDN is needed, as levv cloud will internally resolve the correspondig addresses.
In this case, our sample app requires an environment variable named KV_ADDR
where we must specify the address to connect the cache service and a MYSQL_ADDR
for the database.
storage-app:
image: levvio/apps:sample-storage
environment:
MYSQL_ADDR: "db:3306"
KV_ADDR: "cache:6379"
[...]
Note: other applications might not require that you specify the service port.
Please refer to the full compose specification for all the configuration details, and the Readme for launching this app on your levv cloud project.
As you have seen, levv simplifies inter-service communication, ensuring secure and efficient connections within your projects.