Search code examples
dockerredisdocker-composeredis-cli

How to use redis-cli with Redis on Docker?


Run Redis in Docker

File docker-compose.yml

version: "3.8"

services:
  redis:
    image: redis
    volumes:
      - ./data:/data
    ports:
      - 6379:6379
docker pull redis
docker-compose up
docker-compose up -d
docker container ls
telnet localhost 6379

How to connect to Redis server with redis-cli ?


Solution

  • You can run attach to docker container and use redis-cli directly.

    This command will attach you to the container's shell

    docker exec -it CONTAINER_ID /bin/sh
    

    Then you can use redis-cli just like it installed directly on the host system