Snapchat / KeyDB

A Multithreaded Fork of Redis
https://keydb.dev
BSD 3-Clause "New" or "Revised" License
11.02k stars 564 forks source link

[help] docker keydb-cli can only connect to the default 6379 port ? #815

Closed fishandsheep closed 3 months ago

fishandsheep commented 3 months ago

I have two keydb docker container , one is bound to port 6379 and the other to 6381

➜  ~ docker ps
CONTAINER ID   IMAGE           COMMAND                  CREATED          STATUS          PORTS                                       NAMES
254b46d804fb   eqalpha/keydb   "docker-entrypoint.s…"   26 minutes ago   Up 26 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   mycontainername1
d81d8c13e8c7   eqalpha/keydb   "docker-entrypoint.s…"   30 minutes ago   Up 30 minutes   0.0.0.0:6381->6379/tcp, :::6381->6379/tcp   mycontainername
➜  ~ docker inspect --format '{{ .NetworkSettings.IPAddress }}' mycontainername1
172.17.0.3
➜  ~ docker inspect --format '{{ .NetworkSettings.IPAddress }}' mycontainername 
172.17.0.2

The container bind to 6379 can be connected normally via docker keydb-cli

➜  ~ docker run -it --rm eqalpha/keydb keydb-cli -h 172.17.0.3  -p 6379 -a mypassword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Message of the day:
  KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

172.17.0.3:6379> ping
PONG

But the other one can't be connected.

➜  ~ docker run -it --rm eqalpha/keydb keydb-cli -h 172.17.0.2 -p 6381 -a mypassword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Message of the day:
  KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

Could not connect to Redis at 172.17.0.2:6381: Connection refused
not connected> 

I can connect fine using the local client directly

➜  ~ keydb-cli -p 6381 -a mypassword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Message of the day:
  KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

127.0.0.1:6381> ping
PONG

I've tried several other ports and they refuse to connect. I'm not sure if I'm using docker in a bad way or not. HELP :cry::cry::cry:

michael-grunder commented 3 months ago

You want to use docker exec not docker run to run keydb-cli inside your running container.

$ docker run --rm --name mycontainername  -p 6381:6379 -d eqalpha/keydb
10cdd9cc34d672c75b39c094924e1f3c889b25973696d6b55ab8452daeddbae3
$ docker run --rm --name mycontainername1  -p 6379:6379 -d eqalpha/keydb
0c236966c2daade388e21380dc3e34f49795d1d3779c3e9f48a3edf8b6923a18

Running instances:

CONTAINER ID   IMAGE           COMMAND                  CREATED         STATUS         PORTS                                       NAMES
0c236966c2da   eqalpha/keydb   "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   mycontainername1
10cdd9cc34d6   eqalpha/keydb   "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   0.0.0.0:6381->6379/tcp, :::6381->6379/tcp   mycontainername

And connecting to them:

$ keydb-cli -p 6381 info|grep run_id
run_id:f9a30f414e526625622a94de5fd6500c4b3d10b9
$ docker exec -it mycontainername keydb-cli info|grep run_id
run_id:f9a30f414e526625622a94de5fd6500c4b3d10b9

$ keydb-cli -p 6379 info|grep run_id
run_id:dc9d0470fe9302c7891a188aa7a73c45a3d002c6
$ docker exec -it mycontainername1 keydb-cli info|grep run_id
run_id:dc9d0470fe9302c7891a188aa7a73c45a3d002c6
fishandsheep commented 3 months ago

I see. It's true that I don't fully understand docker yet , docker run eqalpha/keydb keydb-cli connects to port 6379 inside the container, or i can connect directly without specifying a port,

[root@10-7-154-170 ~]# docker run -it --rm eqalpha/keydb keydb-cli -h 172.17.0.2 -a mypassword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Message of the day:
  KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

172.17.0.2:6379> set port 6381
OK
[root@10-7-154-170 ~]# keydb-cli -p 6381 -a mypassword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Message of the day:
  KeyDB has now joined Snap! See the announcement at:  https://docs.keydb.dev/news

127.0.0.1:6381> get port
"6381"