Pull the Redis image
docker search redis
Pull Redis
docker pull redis
View pull results
docker images -a
Create REDIS container
View redis image details
docker inspect redis
Find redis version
docker inspect redis --format='{<!-- -->{json .Config.Env}}' #View REDIS_VERSION
REDIS_VERSION:
[“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,”GOSU_VERSION=1.16″,”REDIS_VERSION=7.2 .2″,”REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-7.2.2.tar.gz”,”REDIS_DOWNLOAD_SHA=ca999be08800edc6d265379c4c7aafad92f0ee400692e4e2d69829ab4b4c3d08″]
Create redis configuration file
Official website download configuration file
If:raw.githubusercontent.com cannot access the hosts file, you can modify it
Create the directory structure as follows:
Download the file from the official website and write it into the redis configuration file. Use the cat command to view the file content:
Modify configuration file
Description of some configuration parameters:
bind 127.0.0.1 #redis binding ip protected-mode no #default yes, turn on protected mode, restrict local access daemonize no #Default no databases 16 #Number of databases (optional) requirepass 123 #Password dir /data/ #Enter the local redis database storage folder (optional) appendonly yes #redis persistence default no (optional)
Create container
docker run -it \ --name redis \ --privileged \ -p 6379:6379 \ -v ~/data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \ -v ~/data/redis/data/:/data \ -v ~/data/redis/log/redis.log:/var/log/redis.log \ -d redis \ /usr/local/etc/redis/redis.conf #Explanation of startup command parameters … –name redis # Alias -p 6379:6379 # Host and container port mapping –privileged=true # Mount container volume directory permissions -v ~/data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf #[Host configuration file]:[Container configuration file] -v ~/data/redis/data/:/data #[Host data storage location]:[Container data storage location] -v ~/data/redis/log/redis.log:/var/log/redis.log #[Host log storage location]:[Container log storage location] -d redis #Run the specified container in the background and return the container ID /usr/local/etc/redis/redis.conf #Specify the absolute path to redis-server to start the redis service with the specified configuration file …
Set up redis to start when docker starts
docker update redis --restart=always
View auto-start status
docker inspect redis --format='{<!-- -->{json .HostConfig.RestartPolicy}}'
Enter redis
docker exec -it redis /bin/bash
Connect redis
redis-cli -a 123456
Command format:
redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h
Server hostname (default: 127.0.0.1). ip address
-pServer port (default: 6379). Server port number
-sServer socket (overrides hostname and port).
-aPassword to use when connecting to the server. Password
-uServer URI. Address in url format
-rExecute specified command N times.
-iWhen -r is used, waits seconds per command.
It is possible to specify sub-second times like -i 0.1.
-nDatabase number. Specify the database
-x Read last argument from STDIN.
-dMulti-bulk delimiter in for raw formatting (default: \\
).
-c Enable cluster mode (follow -ASK and -MOVED redirections).
–raw Use raw formatting for replies (default when STDOUT is
not a tty).
–no-raw Force formatted output even when STDOUT is not a tty.
–csv Output in CSV format.
–stat Print rolling stats about server: mem, clients, …statistics continuous output
–latency Enter a special mode continuously sampling latency.
If you use this mode in an interactive session it runs
forever displaying real-time stats. Otherwise if –raw or
–csv is specified, or if you redirect the output to a non
TTY, it samples the latency for 1 second (you can use
-i to change the interval), then produces a single output
and exits. Delay statistics
–latency-history Like –latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
–latency-dist Shows latency as a spectrum, requires xterm 256 colors.
Default time interval is 1 sec. Change it using -i.
–lru-testSimulate a cache workload with an 80-20 distribution.
–replica Simulate a replica showing commands received from the master.
–rdbTransfer an RDB dump from remote server to local file. Export rdb file
–pipe Transfer raw Redis protocol from stdin to server.
Pipeline mode
–pipe-timeoutIn –pipe mode, abort with error if after sending all data.
no reply is received withinseconds.
Default timeout: 30. Use 0 to wait forever.
Pipe timeout
–bigkeys Sample Redis keys looking for big keys.
–hotkeys Sample Redis keys looking for hot keys.
only works when maxmemory-policy is *lfu.
–scan List all keys using the SCAN command. Get all the keys of the server
–patternUseful with –scan to specify a SCAN pattern.
Regular expression used in scan command
–intrinsic-latencyRun a test to measure intrinsic system latency.
The test will run for the specified amount of seconds.
–evalSend an EVAL command using the Lua script at .
–ldb Used with –eval enable the Redis Lua debugger.
–ldb-sync-mode Like –ldb but uses the synchronous Lua debugger, in
this mode the server is blocked and script changes are
not rolled back from the server memory.
–cluster[args…] [opts…]
Cluster Manager command and arguments (see below).
–verbose Verbose mode.
–no-auth-warning Don’t show warning message when using password on command
line interface.