Marco Stramezzi
Marco Stramezzi

Reputation: 2271

Interact with redis container started with docker compose

I have a docker compose file that links my server to a redis image:

version: '3'

services:
    api:
        build: .
        command: npm run dev
        environment: 
            NODE_ENV: development
        volumes:
            - .:/home/node/code
            - /home/node/code/node_modules
            - /home/node/code/build/Release
        ports: 
            - "1389:1389"
        depends_on: 
            - redis

    redis:
        image: redis:alpine

I am wondering how could I open a redis-cli against the Redis container started by docker-compose to directly modify ke/value pairs. I tried with docker attach but it does not open any shell.

Upvotes: 0

Views: 616

Answers (3)

Gautam
Gautam

Reputation: 1119

Using /bin/bash as the command (as suggested in the accepted solution) doesn't work for me with the latest redis:alpine image on Linux.

Instead, this worked:

docker exec -it your_container_name redis-cli

Upvotes: 0

David Maze
David Maze

Reputation: 158647

Install the Redis CLI on your host. Edit the YAML file to publish Redis's port

services:
    redis:
        image: redis:alpine
        ports: ["6379:6379"]

Then run docker-compose up to redeploy the container, and you can run redis-cli from the host without needing to directly interact with Docker.

Upvotes: 1

atline
atline

Reputation: 31564

Use docker exec -it your_container_name /bin/bash to enter into redis container, then execute redis-cli to modify key-value pair.

See https://docs.docker.com/engine/reference/commandline/exec/

Upvotes: 1

Related Questions