Tom
Tom

Reputation: 9643

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 

Upvotes: 7

Views: 10291

Answers (3)

Khuram
Khuram

Reputation: 1850

Although, the answers are already given but I'm going to explain it a bit more with details for the newbies of the docker having such issues.

The command docker exec is used to run a command from the terminal of your machine which for a container.

You can also get the detailed help for the command by executing the command docker exec --help:

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container

Options:
  -d, --detach               Detached mode: run command in the background
  --detach-keys string   Override the key sequence for detaching a
                         container
  -e, --env list             Set environment variables
  --help                 Print usage
  **-i, --interactive          Keep STDIN open even if not attached**
  --privileged           Give extended privileges to the command
  **-t, --tty                  Allocate a pseudo-TTY**
  -u, --user string          Username or UID (format:
                         <name|uid>[:<group|gid>])

This docker exec [OPTIONS] CONTAINER COMMAND [ARG...] clearly shows that you need CONTAINER and the COMMAND along with the arguments. For example: docker exec -it app_placements-store_1 redis-cli

Note: I have displayed the '-iandtas bold in the output ofdocker exec --help` to so you can read it why we are using these options

Upvotes: 0

ajtrichards
ajtrichards

Reputation: 30565

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.

Upvotes: 17

Martin
Martin

Reputation: 3114

Use docker exec to execute commands inside a running container:

docker exec -it app_placements-store_1 redis-cli

Upvotes: 9

Related Questions