Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Redis CLI inside a Docker container

Tags:

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?

like image 430
Andrzej Gis Avatar asked Jan 15 '19 19:01

Andrzej Gis


People also ask

How can I view Redis data in docker container?

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.

How use Redis command-line?

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.


2 Answers

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

like image 156
Ortomala Lokni Avatar answered Sep 23 '22 07:09

Ortomala Lokni


  1. Run redis container at 6379 port with the name redis in detached mode.

docker run --name redis -p 6379:6379 -d redis

  1. Run the redis-cli command in the container.

docker exec -it redis redis-cli

like image 23
Faruk AK Avatar answered Sep 23 '22 07:09

Faruk AK