0

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.

0

3 Answers 3

1

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/

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.