wasmedge-db-examples
wasmedge-db-examples copied to clipboard
Accessing DB by URL when using docker compose
Hello everyone,
Sorry for newbie question, when I run redis and postgres examples locally everything works fine, but when I tried to run redis and postgres examples by using docker the following errors appear:
-
For redis example
-
For postgres example
After studying "A complete microservice demo example which works fine, I added DNS_SERVER: 127.0.0.11:53 variable in docker-compose file at postgres and redis example.
Postgres example works now.
But this trick not works for redis example. If you have some time, could you please help me to manage with issue in redis example?
Thanks, Roman
Can you send your Docker compose file for the Redis app? Thanks!
Is it possible that the Redis container has not had the time to start up when Wasm service tried to connect? Perhaps introduce a delay like the health check you had with Postgres?
Hello @juntao
I've added healthcheck for "cache" service, unfortunately it does not help.
The docker-compose and healthcheck files I used were uploaded into attachment
Thanks, Roman
I conducted an experiment by attempting to into other the ubuntu container, but running in the same service (same network) environment, to use redis-cli for accessing the cache. However, I was unable to establish a connection. And redis-cli directly from the host worked fine. I suspect there might be a configuration missing in the Docker network rather than an issue with the wasm runtime itself.
But I'll continue to see what else can help clarify the issue.
Hello @CaptainVincent
Thank you for your response, I'll also play with docker network config, if I found smth interesting, I'll let you know.
Thanks, Roman
Hello @CaptainVincent
I still don't know that the true reason of this issue, but I was able to make some progress. When I inspected "cache" container and used the "IPAddress" directly in my docker compose everything become works fine, but using any network aliases invokes "os error 85" as it was before.
Thanks, Roman
Thank you Roman for investigating this.
It is interesting that the gateway IP address, not the server's IP address, worked for you. I wonder if you could start a regular Ubuntu container in the same compose and have it nslookup the DNS name cache? My guess is that it cannot -- but that would give us a simple case to raise an issue for the Docker team.
Hello @juntao
I forgot to mention that both IPAddress and Gateway values work. Also I followed your recommendation and run "nslookup" "cache" command from Ubuntu container put in the same compose and it shows the appropriate IPAddress of cache service. But I not understand why "REDIS_URL: redis://cache/" not work :-)
Thanks, Roman
You know one thing I could think of is to change the host name from cache to something like rediscachehost because the word "cache" might have special meaning in Docker compose?
Hello @juntao
I already tried this trick, but unfortunately it does not help :-)
Thanks, Roman
Hello @juntao
I've some progress regarding this issue. If I use AsyncComand instead Command, with switching on appropriate feature for redis_wasi in Cargo.tom redis_wasi = { version = "0.22.3", features = ["tokio-comp"] } everything works fine.
Changes in code:
let mut con = client.get_async_connection().await?;
let _ : () = con.set("current_time", time).await?;
let value : String = con.get("current_time").await?;
Thanks, Roman