Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter a redis-server shell inside a running docker-compose container

I want to see if the running redis-server container status. So i want to execute info in a redis shell and see if the redis slave is in sync with the remote redis master.

My docker-compose file lists the redis as follows:

  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"

Running docker-compose ps I can see it the container is up and running:

app_placements-store_1   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp 

I tried to execute:

docker-compose run --rm redis-cli

And got:

ERROR: No such service: redis-cli

I think this is understandable since there's no redis-cli container. I'm trying to tag along to the running redis-server instead but don't have any idea how to do that.

UPDATE

I can view the logs by executing:

docker-compose logs -f --tail 500 placements-store

And I do get some information like below, but I'm looking for more information and something that I can more easily control from the outside:

placements-store_1  | 1:S 06 Feb 19:16:35.427 * Connecting to MASTER mo-api.mydomain.com:6379
placements-store_1  | 1:S 06 Feb 19:16:35.589 * MASTER <-> SLAVE sync started
placements-store_1  | 1:S 06 Feb 19:16:35.889 * Non blocking connect for SYNC fired the event.
placements-store_1  | 1:S 06 Feb 19:16:36.189 * Master replied to PING, replication can continue...
placements-store_1  | 1:S 06 Feb 19:16:36.790 * Partial resynchronization not possible (no cached master)
placements-store_1  | 1:S 06 Feb 19:16:37.091 * Full resync from master: 5ada1d8c65fd49d67d931bea66530a169ce83a40:29442
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: receiving 60 bytes from master
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Flushing old data
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Loading DB in memory
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Finished with success 
like image 955
Tom Avatar asked Feb 07 '17 07:02

Tom


People also ask

How do I connect to a local redis server from a docker container?

To connect to a Redis instance from another Docker container, add --link [Redis container name or ID]:redis to that container's docker run command. To connect to a Redis instance from another Docker container with a command-line interface, link the container and specify the host and port with -h redis -p 6379.


Video Answer


2 Answers

You need to log on to the container using docker exec (as mentioned in another answer - not sure if the command is 100% correct as it may just run redis-cli then exit).

I would run the following command:

docker exec -it app_placements-store_1 sh

That will log you on to the container. You can then run redis-cli from the command prompt.

like image 178
ajtrichards Avatar answered Oct 18 '22 02:10

ajtrichards


Use docker exec to execute commands inside a running container:

docker exec -it app_placements-store_1 redis-cli

like image 43
Martin Avatar answered Oct 18 '22 01:10

Martin