Hi all!
I am trying to expose a redis container service to the host system. But I do lack some basic fundamentals I guess.
Imagine following dagger approach:
async def main():
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
redis_srv = (
client.container()
.from_("redis")
.with_exposed_port(6379)
.with_mounted_cache("/redis_data", client.cache_volume("my-redis"))
.with_workdir("/redis_data")
.as_service()
)
redis_cli = (
client.container()
.from_("redis")
.with_service_binding("redis-srv", redis_srv)
.with_entrypoint(["redis-cli", "-h", "redis-srv"])
)
await redis_cli.with_exec(["set", "foo", "abc"]).with_exec(["save"]).stdout()
tunnel = await client.host().tunnel(redis_srv).start()
endpoint = await tunnel.endpoint()
return endpoint
Within the main I am able to query the service etc. as expected. However, outside I am not. I guess I do miss something obvious.
I thought, that I might be able to call the service like so:
endpoint = await main()
host, port = endpoint.split(":")
r = redis.Redis(host=host, port=6379, decode_responses=True)
print(r.get("foo"))
But in this case, I get a connection error.
Thanks for the help ๐