0

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 ?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • You should just be able to run it normally, since you've published the Redis port 6379 out of the container on its normal port number. What happens if you just run it? – David Maze Oct 10 '20 at 19:19

1 Answers1

4

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

n0nvme
  • 1,248
  • 8
  • 18
  • I run `docker exec -t c53e7198f414 /bin/sh` then I cannot type anything. https://user-images.githubusercontent.com/1328316/95659826-fa9e5580-0b4d-11eb-82f3-94504bac3d67.png How to typing? – Vy Do Oct 10 '20 at 16:12
  • 1
    You need to use cli arg `-it` which means interactive pseudo-tty. without `-i` you cannot perform any interaction with executed command. UPDATE: docs reference for `docker exec` https://docs.docker.com/engine/reference/commandline/exec/#options – n0nvme Oct 10 '20 at 16:15