安装步骤:
[root@localhost conf]# docker pull redis:6.0.8
6.0.8: Pulling from library/redis
Digest: sha256:21db12e5ab3cc343e9376d655e8eabbdbe5516801373e95a8a9e66010c5b8819
Status: Image is up to date for redis:6.0.8
docker.io/library/redis:6.0.8
[root@localhost conf]# mkdir -p /app/redis
[root@localhost conf]# cd /app/redis/
[root@localhost redis]# vi redis.conf
[root@localhost redis]# vi redis.conf
本地新建一个redis文件,并修改相关配置
[root@localhost redis]# docker run -p 6379:6379 --name myredis --privileged=true -v /app/redis/redis.conf:/etc/redis/redis.conf -v /app/redis/data:/data -d redis:6.0.8 redis-server /etc/redis/redis.conf
2c0405e33fd9e701f24d38ee2c6c548da57b0269ec629791f386d71caa2f20ee
[root@localhost redis]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c0405e33fd9 redis:6.0.8 "docker-entrypoint.s…" 19 seconds ago Up 16 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp myredis
7e477af1061c mysql:5.7 "docker-entrypoint.s…" 29 minutes ago Up 29 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
f5bbe411a1ed registry "/entrypoint.sh /etc…" 5 hours ago Up 5 hours 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp gallant_driscoll
[root@localhost redis]# docker exec -it myredis
"docker exec" requires at least 2 arguments.
See 'docker exec --help'.
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Execute a command in a running container
[root@localhost redis]# docker exec -it myredis /bin/bash
root@2c0405e33fd9:/data# redis-cli
127.0.0.1:6379> set k1 v1
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> select 10
OK
127.0.0.1:6379[10]> select 1
OK
127.0.0.1:6379[1]> select 12
OK
127.0.0.1:6379[12]> select 18
(error) ERR DB index is out of range
127.0.0.1:6379[12]> select 18
(error) ERR DB index is out of range
127.0.0.1:6379[12]> exit
root@2c0405e33fd9:/data# exit
exit
修改数据库个数
[root@localhost redis]# docker restart myredis
myredis
[root@localhost redis]# docker exec -it myredis /bin/bash
root@2c0405e33fd9:/data# redis-cli
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> select 18
OK
127.0.0.1:6379[18]>