wasmedge-db-examples icon indicating copy to clipboard operation
wasmedge-db-examples copied to clipboard

Accessing DB by URL when using docker compose

Open RomanShushakov opened this issue 1 year ago • 12 comments

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:

  1. For redis example redis_example_issue

  2. For postgres example postgres_example_issue

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_changes

Postgres example works now. postgres_example_works

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

RomanShushakov avatar Dec 02 '23 07:12 RomanShushakov

Can you send your Docker compose file for the Redis app? Thanks!

juntao avatar Dec 02 '23 10:12 juntao

Thank you for response, sure

docker-compose.txt

RomanShushakov avatar Dec 02 '23 10:12 RomanShushakov

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?

juntao avatar Dec 02 '23 20:12 juntao

Hello @juntao

I've added healthcheck for "cache" service, unfortunately it does not help.

redis_example_issue(1)

The docker-compose and healthcheck files I used were uploaded into attachment

Thanks, Roman

docker-compose.txt redis.txt

RomanShushakov avatar Dec 02 '23 21:12 RomanShushakov

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.

CaptainVincent avatar Dec 04 '23 07:12 CaptainVincent

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

RomanShushakov avatar Dec 04 '23 07:12 RomanShushakov

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.

image

docker-compose.txt

Thanks, Roman

RomanShushakov avatar Dec 08 '23 09:12 RomanShushakov

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.

juntao avatar Dec 08 '23 17:12 juntao

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

docker inspect

nclookup cache

docker-compose.txt

RomanShushakov avatar Dec 09 '23 09:12 RomanShushakov

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?

juntao avatar Dec 09 '23 09:12 juntao

Hello @juntao

I already tried this trick, but unfortunately it does not help :-)

Thanks, Roman

docker-compose.txt

RomanShushakov avatar Dec 09 '23 10:12 RomanShushakov

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

RomanShushakov avatar Dec 17 '23 17:12 RomanShushakov