The most detailed Docker installation of Redis in history (including illustrations of each step) practical + redis password reset related

Refer to the original link: https://blog.csdn.net/weixin_45821811/article/details/116211724

1. Docker searches for redis images

  • Command: docker search <image name>
 docker search redis

Insert image description here

You can see that there are many redis images. Since there is no specified version here, the latest version is downloaded by default. redis latest.

2. Docker pulls the image

  • Command: :docker pull <image name>:<version number>
docker pull redis

Insert image description here

3. Docker mounting configuration file

The next step is to mount the redis configuration file and start the redis container in the configuration file. (Mounting: Associating the host's files with the internal directory of the container and binding them to each other. Modifying the files in the host will also modify the internal files of the container) 1)
Mount the redis configuration file

2) Mount the persistence file of redis (for data persistence).
My configuration file is placed in
the redis.conf file location under liunx: /home/redis/myredis/redis.conf
The redis data file location under liunx: /home/redis/myredis/data The
location can be chosen by yourself.
Insert image description here

The mkdir -p /home/redis/myredis command directly creates the /home/redis/myredis folder if it does not exist.
Insert image description here
I uploaded myredis.conf manually. (The file is at the end of the article, and the standard file of redis.conf can also be found on the redis official website)
Insert image description here

4. Start the redis container


docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis -v /home/redis/myredis/myredis.conf:/etc/redis/redis.conf -v /home/redis/myredis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 000415

  1. –restart=always Always start at boot
  2. –log is for logs
  3. -p 6379: 6379 mounts port 6379 (the bold one is the container port, : in front is the host port)
  4. –name Give this container a name
  5. -v data volume mounting
    ————/home/redis/myredis/myredis.conf:/etc/redis/redis.conf Here is where
    myredis.conf under the liunx path and redis.conf under redis are mounted together. .
    –———— /home/redis/myredis/data:/data This is the same as above
  6. -d redis means starting redis in the background
  7. redis-server /etc/redis/redis.conf
    starts redis with the configuration file, loads the conf file in the container, and finally finds the mounted directory /etc/redis/redis.conf,
    which is /home/redis/ under liunx myredis/myredis.conf
  8. –appendonly yes turns on redis persistence
  9. –requirepass 000415 Set the password (if you are
    connecting through the internal docker container, you can set it or not. But if you want to open it to the outside world, you must set it. I have been screwed. You can read this article "Alibaba Cloud Server" Poisoning 'Kirito666' experience")
  10. success interface
    Insert image description here

5. Test

1. Check the startup status through the docker ps command

docker ps -a |grep myredis # 通过docker ps指令查看启动状态,是否成功.

2. View container running logs

docker logs --since 30m <容器名>

Here --since 30m is to view the log status of this container within 30 minutes.

docker logs --since 30m myredis

Insert image description here

3. Connect inside the container for testing
and enter the container

Command: docker exec -it <container name> /bin/bash

The redis-cli that follows here directly enters the command above.

docker exec -it myredis redis-cli

After entering, I directly enter the view command:
there may be an enterable or inaccessible status
Insert image description here
Insert image description here
error indicating that there is no permission verification. (Because a password is set.)
Verify password:

config get requirepass

Insert image description here

6. Configuration file

# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#bind 127.0.0.1

protected-mode no

port 6379

tcp-backlog 511

requirepass 000415

timeout 0

tcp-keepalive 300

daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile ""

databases 30

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir ./

replica-serve-stale-data yes

replica-read-only yes

repl-diskless-sync no

repl-disable-tcp-nodelay no

replica-priority 100

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

appendonly yes

appendfilename "appendonly.aof"

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble yes

lua-time-limit 5000

slowlog-max-len 128

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

stream-node-max-bytes 4096
stream-node-max-entries 100

activerehashing yes

hz 10

dynamic-hz yes

aof-rewrite-incremental-fsync yes

rdb-save-incremental-fsync yes


7. Docker deletes Redis

After teaching you how to install it, we also need to learn how to uninstall it, otherwise we will not be able to become skilled workers (manual dog head)
7.1 Delete the redis container

  • View all running containers:
docker ps -a

Insert image description here

  • `Stop running Redis
docker stop myredis # myredis 是我启动redis 命名的别

Insert image description here

  • Delete the redis container:
docker rm myredis

Insert image description here
7.2. Delete the Redis image.
After deleting the container, we start to delete the redis image.

  • View all mirror commands:
docker images
  • Delete the image command docker rmi <container id>
docker rmi 739b59b96069 # 这是我镜像redis id

Insert image description here
You can see that the Redis image has been deleted.

————————————————————————————————————————————
Supplementary space: Because in The redis password will be cleared during actual use. Some content will be supplemented below.
Refer to the original link: https://blog.csdn.net/Lijunhaodeboke/article/details/126346067

1. Docker sets redis password

Method 1: Create a redis container and set a password

docker run -itd --name redis-6379 -p 6379:6379 redis --requirepass 123456

Note: --name (启动容器的名称) -p 映射端口:redis启动端口 redis --requirepass 启动密码
Method 2: Create a password or change the password for existing redis:

#1.进入redis的容器
docker exec -it 容器ID bash

#2.进入redis目录
cd /usr/local/bin

#3.运行命令:
redis-cli

#4.查看现有的redis密码:
config get requirepass

#5.设置redis密码
config set requirepass 密码

Insert image description here
This is because redis has set a password, and we need to use the password for verification before operating the redis client. Otherwise, we do not have the authority to operate the redis cache database.

auth 密码

Insert image description here
Clear redis password

#将密码置为空字符串即可
config set requirepass ""

***Clear redis password methodconfig set requirepass ""Insert image description here

Guess you like

Origin blog.csdn.net/budaoweng0609/article/details/129004595