First, enter the command docker pull redis
to install the latest version of Redis locally.
Enter the following command to start Redis in the background (Note: this command is a single command).
The name after --name
is the name of the Redis container, which can be changed as desired.
docker run -p 6379:6379 --name mars1 --privileged=true
-v /app/redis/redis.conf:/etc/redis/redis.conf
-v /app/redis/data:/data
-d redis redis-server /etc/redis/redis.conf
This command can also solve the problem of data loss that occurs after deleting the Redis container. To recover the data, simply rerun the command.
Run the command docker ps
to see that Redis is running.
Then execute the command docker exec -it mars1 /bin/bash
, and Redis is successfully running.