Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling redis-cli in docker-compose setup

I run the official Redis image https://hub.docker.com/_/redis/ in a docker-compose setup.

myredis:   image: redis 

How can run redis-cli with docker-compose on that image?
I tried the following, but it didn't connect:

docker-compose run myredis redis-cli > Could not connect to Redis at 127.0.0.1:6379: Connection refuse 

The docs of the image says that I should run:

docker run -it --rm \ --link some-redis:redis \ redis \ sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"' 

How does this translate to docker-compose run?

like image 761
ivoba Avatar asked Oct 23 '15 14:10

ivoba


People also ask

How run Redis-CLI?

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.

Where is Redis config file docker?

It just located at root path. Note that select the branch match your version. Then you can custom the config file base on the example config file above. Then run the command docker run -v /path/to/your/custom/config/redis.


2 Answers

That would override the default CMD [ "redis-server" ]: you are trying to run redis-cli on a container where the redis-server was never executed.

As mentioned here, you can also test with:

docker exec -it myredis redis-cli 

From docker-compose, as mentioned in this docker/compose issue 2123:

rcli:   image: redis:latest   links:     - redis   command: >      sh -c 'redis-cli -h redis ' 

This should also works:

rcli:   image: redis:latest   links:     - redis   command: redis-cli -h redis 

As the OP ivoba confirms (in the comments), the last form works.
Then:

docker-compose run rcli 

ivoba also adds:

docker-compose run redis redis-cli -h redis works also when the containers are running.
This way its not necessary to declare a separate rcli container.

like image 147
VonC Avatar answered Sep 21 '22 02:09

VonC


You can also use this command:

docker-compose run myredis redis-cli -h myredis 
like image 26
hamidfzm Avatar answered Sep 22 '22 02:09

hamidfzm