Installing Redis with Docker
Installing Redis with Docker
If you want a simple setup for learning or experimentation, using Docker to install Redis is recommended.
Downloading the Redis Docker image
Run the following command to download Redis Docker. This example uses the alpine version.
If you want another version tag, refer to https://hub.docker.com/_/redis/tags.
% docker pull redis:alpine
After downloading, check the image and you can see the list as follows.
% docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis alpine a4cf5af74f5e 2 days ago 30.4MB
Creating and running a Redis Docker container
Run the following command.
% docker run -d -p 6379:6379 --name=redis redis:alpine
-p: specify the port to expose on the host--name: specify the container name
After running it, check the running container.
% docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1df277cb625c redis:alpine "docker-entrypoint.s…" 30 seconds ago Up 29 seconds 0.0.0.0:6379->6379/tcp redis
Connecting to Redis Docker
Connecting inside the Redis Docker container
Before connecting to Redis, connect inside the Docker container where Redis is installed.
% docker exec -it redis /bin/bash
If you see an error message like the following, try connecting with /bin/sh.
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
% docker exec -it redis /bin/sh
Connecting to Redis
Once connected inside the container, connect to Redis. Use the redis-cli command to connect to Redis.
/data # redis-cli
127.0.0.1:6379>
When connected, the prompt changes to IP:port> as shown above.
To check Redis information, enter info as follows.
127.0.0.1:6379> info
# Server
redis_version:7.0.10
... omitted ...
Press Ctrl+C to exit.