I have Redis running inside of a docker container.
docker run --rm -d --name "my_redis" redis
I'd like to access it via CLI:
If I run docker exec -it my_redis redis-cli
the console becomes unresponsive until I leave the container (Ctrl + P, Ctrl + Q)
C:\Users\Andrzej>docker exec -it my_redis redis-cli // nothing here until I go Ctrl + P, Ctrl + Q exec attach failed: error on attach stdin: read escape sequence C:\Users\Andrzej>
If I run docker exec -it my_redis sh
and then run redis-cli
from inside of the container it works.
C:\Users\Andrzej>docker exec -it my_redis sh # redis-cli 127.0.0.1:6379> set hello world OK 127.0.0.1:6379> get hello "world" 127.0.0.1:6379>
My OS is Windows 10.
Is there any way to fix docker exec -it my_redis redis-cli
behavior?
UPDATE
When the console gets unresponsive and I click "arrow up" key exactly 11 times I get the Redis cli. This is 100% reproducible. What kind of voodoo magic is that?
If you'd like to spin up this container and experiment, simply enter docker run -d -p 6379:6379 redislabs/redismod in your terminal. You can open Docker Desktop to view this container like we did earlier on. You can view Redis' curated modules or visit the Redis Modules Hub to explore further.
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.
Run a redis container in detached mode:
docker run -d redis
Run redis-cli
on it:
docker exec -it e0c061a5700bfa400f8f24b redis-cli
where e0c061a5700bfa400f8f24b
is the id of the container.
According to the documentation:
Detached (-d)
To start a container in detached mode, you use -d=true or just -d option. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the --rm option. If you use -d with --rm, the container is removed when it exits or when the daemon exits, whichever happens first.
.
--interactive , -i Keep STDIN open even if not attached
--tty , -t Allocate a pseudo-TTY
docker run --name redis -p 6379:6379 -d redis
docker exec -it redis redis-cli
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With