The most detailed actual combat of docker installation redis in history (including the illustration of each step)

Time:2022-5-25

Not only teach you to install, but also teach you to delete.

Each line of command is illustrated, which is absolutely understandable.

If you are interested in building a redis cluster, you can take a look at this article
Docker builds redis cluster cluster environment
Hope to help you

1、 Docker searches redis images

Command: docker search < image name >

docker search redis

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

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

2、 Docker pull image

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

docker pull redis

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

3、 Docker mount profile

The next step is to mount the redis configuration file toStart redis container in profile mode(Mount: that is, the host file is associated with the internal directory of the container and bound to each other. If the file is modified in the host, the internal file of the container is also modified)

1) . mount the redis configuration file

2) . mount the persistent file of redis (for data persistence).

My profile is placed in

Redis.com under liunx Conf file location: / home / redis / myredis / redis conf

Redis data file location under liunx: / home / redis / myredis / data

You can choose the location by yourself

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

mkdir -p /home/redis/myredisIf the command does not exist, directly create the / home / redis / myredis folder

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

myredis. I uploaded conf manually. (the file is at the end of the text, and the standard file of redis.conf can also be found on the official website of redis)

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

4、 Start 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
  2. – log is the of log
  3. -P 6379: 6379 mount port 6379 out
  4. – name give the container a name
  5. -V data volume mount
    • /home/redis/myredis/myredis. conf:/etc/redis/redis. Conf here is myredis. Conf under the liunx path Redis under conf and redis Conf is mounted together.
    • /Home / redis / myredis / data: / data is the same as above
  6. -D redis means that redis is started 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 alsoIt’s / home / redis / myredis / myredis under liunx conf
  8. – appendonly yes enable redis persistence
  9. – requirepass 000415 set password(if you are connected inside the docker container, you can set it or not. But if you want to open it to the outside world, you must set it. I’ve been engaged in it, so you can read this article“Alibaba cloud server poisoning ‘kirito666’ experience”)
  10. Successful interface

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

5、 Testing

1. Check the startup status through the docker PS command

Docker PS - a | grep myredis # check the startup status through the docker PS command to see if it is successful

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

2. View container operation log

Command: docker logs — since 30m < container name >

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

docker logs --since 30m myredis

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

3、Test the internal connection of the container

Enter container

Command: docker exec – it < container name > / bin / Bash

The redis cli followed here is to directly input the command on it.

docker exec -it myredis redis-cli

After entering, I directly enter the view command:

The most detailed actual combat of docker installation redis in history (including the illustration of each step)
Error is no permission verification.(because the password is set.)

Verify password:

Auth password

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

Check whether the current redis password is set:(it can only be entered after passing the verification)

config get requirepass

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

6、 Configuration file

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 [email protected]

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

The most detailed actual combat of docker installation redis in history (including the illustration of each step)

7、 Dock delete redis

After teaching you how to load, we have to learn how to unload, otherwise we can’t become skilled workers (manual dog head)

6.1. Delete redis container

  1. View all running containers:
    Command:

    docker ps -a
    

    The most detailed actual combat of docker installation redis in history (including the illustration of each step)

  2. Stopped redis

    Stop command:Docker stop < container name >

    Docker stop myredis # myredis is named after I started redis

    The most detailed actual combat of docker installation redis in history (including the illustration of each step)

  3. Delete redis container:

    Delete container command:Docker RM < container name >

    docker rm myredis
    

    The most detailed actual combat of docker installation redis in history (including the illustration of each step)

6.2. Delete redis image

After deleting the container, we begin to delete itRedis image

  1. View all mirror commands:
    docker images

    The most detailed actual combat of docker installation redis in history (including the illustration of each step)

  2. Delete mirror commandDocker RMI < container ID >

    Docker RMI 739b59b96069 # this is my image redis ID

    The most detailed actual combat of docker installation redis in history (including the illustration of each step)

    You can see that the redis image has been deleted.

Daily self talk

I downloaded it last time, but because there was no record, I had to check it again. Finally, I wrote this article

FuckDocker installs redisBlog, hope to help you.