Docker installs Redis and starts it as a configuration file
[Step 1] Create Docker Network
The default network is docker0. The network inside the container can only be accessed through the IP address of the container, not through the container name. Therefore, all the software we install and business projects we deploy will use the network we create.
Create a docker network, named mynet, and the network segment is 172.19.0.0/16
After downloading, modify the redis.conf configuration file
#Bind 127.0.0.1 # Comment out this part so that Redis can access it externallyProtected mode no # Change to no, remove the protection mode, and make the Internet accessibleDaemonize no # Change to no, start without daemon threadRequirepass 123456 # passwordAppendonly yes # Redis persistence, default is no
Create a new directory/soft/redis/conf on the host to store the Redis configuration files and data
Copy or move the configuration file to the/soft/redis/conf directory
-P 6379:6379 # Map port 6379 in the container to host port 6379
-V/soft/redis//conf/redis.conf:/etc/redis/redis.conf # Use the file to the host/soft/redis/conf/redis.cong as the configuration file of the Redis container/etc/redis/redis.conf
-V/soft/redis/data:/data # Put the redis persistent data in the host directory/mydata/redis/data for data backup
Redis server/etc/redis/redis. conf # This is a key configuration. Redis is not started without configuration, but is started according to the configuration of redis.conf
– appendonly yes # Data persistence after Redis is started
--Privileged=true # Solve the problem of container without permission
[Step 3] Enter the Redis container test:
docker exec -it myredis /bin/bash
Log in to the Redis cli console, enter the password verification, set the key, and obtain the key:
redis-cliauth '123456'set key1 value1get key1
[root@localhost data]# docker exec -it myredis /bin/bashroot@98c45e178eea:/data# redis-cli 127.0.0.1:6379> get v1(error) NOAUTH Authentication required.127.0.0.1:6379> auth 123456OK127.0.0.1:6379> get v1"1"127.0.0.1:6379>
The articles not noted in this website are all original and adoptedCC BY-NC-SA 4.0Authorization Agreement,Please indicate the source for reprinting, thank you!If the content of this site is helpful to you, please subscribeLongxing Blog, chat (share) the daily experience.
There are 0 comments
The blogger has turned off the comment function of this article