Location: Changsha, Hunan province

Author: Blogger

Not only does it teach you to install, but it also teaches you to remove.

Every line of command is illustrated, so you can definitely understand it.

Docker searches for Redis images

Docker search < image name >

docker search redis
Copy the code

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

Docker pulls the image

: docker pull < image name >:< version number >

docker pull redis
Copy the code

Docker mounts configuration files

The next step is to mount the redis configuration file to start the Redis container. == (mount: the host file is associated with the internal directory of the container and bound to each other, if you modify the file in the host, you will also modify the internal file of the container) ==

2. Mount the redis persistent file (for data persistence).

My profile is placed in

Redis under Linux. The conf file location: / home/redis/myredis/redis. Conf

The redis data file in liunx is located in /home/redis/myredis/data

The mkdir -p /home/redis/myredis command creates the /home/redis/myredis folder if it does not exist

Myredis.conf is manually uploaded by me. (Document at the end)

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
Copy the code
  1. –restart=always Starts at startup
  2. –log is for logging
  3. -p 6379:6379 Mounts port 6379
  4. –name Gives the container a name
  5. -v Indicates that the data volume is attached
    • / home/redis/myredis myredis. Conf: / etc/redis/redis. Conf. Here is the Linux directory path myredis under the conf and redis redis. Conf mount together.
    • / home/redis/myredis/data: / data the same as above
  6. -d redis Indicates that redis is started in the background
  7. Redis-server /etc/redis/redis.conf start redis with the configuration file, load the conf file in the container, Eventually found is mounted directory/etc/redis/redis conf is under Linux/home/redis/myredis myredis. Conf
  8. Appendonly Yes Enable redis persistence
  9. ==– requirePass 000415 Set password == (If you are connecting from inside a Docker container, this is optional. But if you want to open it to the outside, it must be set, I was screwed, you can see this article “Ali Cloud server poisoning ‘Kirito666’ experience”)
  10. Successful interface

Five, the test

1. View the startup status through the Docker PS command

docker ps -a |grep myredis Use the Docker PS command to check the startup status and see if it is successful.
Copy the code

2. View container run logs

Docker logs –since 30m

Here –since 30m is to look at the logs of this container within 30 minutes.

docker logs --since 30m myredis
Copy the code

3,Container internal connections are tested

Into the container

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

“Redis -cli” is used to type the command directly.

docker exec -it myredis redis-cli
Copy the code

After entering, I directly type the view command:

Erro is not authorized to authenticate.(Because the password is set.)

Verify password:

Auth passwordCopy the code

Check whether redis has a password:

config get requirepass
Copy the code

Vi. Configuration files

myredis.conf

# 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 wangyihui123@

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! [insert picture description here] (HTTP: / / https://img-blog.csdnimg.cn/9163e22988bb4e849041728035e8b1c6.png#pic_center)

Copy the code

Docker removes Redis

6.1 deleting a Redis container

  1. View all running containers: command:

    docker ps -a
    Copy the code

  2. Stop running Redis

    Docker stop < container name >

    docker stop myredis # myredis is the name I started redis with
    Copy the code

  3. To delete a Redis container:

    Delete container: ==docker rm < container name >==

    docker rm myredis
    Copy the code

6.2 Deleting a Redis Image

After we delete the container, we start to delete the Redis image.

  1. Command to view all mirrors:

docker images

  1. Docker rmi < container ID >

    docker rmi 739b59b96069 # This is my mirror redis ID
    Copy the code

    You can see that the Redis image has been deleted.

Daily self-talk

It was downloaded last time, but there was no record, so when this secondary operation was done, it was all kinds of checks before it was done. Finally, I wrote down this blog of actual Docker installation redis, hoping to help you.

If there is anything wrong, please kindly advise me. I would appreciate it.

Of course, if there is doubt or don’t understand the place, leave a comment, will give a reply in time.