Docker use tutorial related series catalog
table of Contents
Modify the configuration file redis.conf
Docker download, install and run redis
Get redis.conf
Redis official website: https://redis.io/
Go to the official website, download the specified redis version , and unzip it to get redis.conf
Version 5.0.5 is used here
https://download.redis.io/releases/
Choose the version you want
Unzip to get redis.conf
Pit one:
The redis version obtained on the official website must be the same as the redis version installed by docker. The redis configuration files of different versions may be different.
Modify the configuration file redis.conf
Open redis verification requirepass 123456
Allow redis to connect to the outside world
#bind 127.0.0.1 要注释掉
Enable redis data persistence
appendonly yes
Pit 2:
This configuration will conflict with the -d parameter in dcoker run, causing the container to never start
daemonize yes 要注释
Create redis directory
cd /usr
mkdir redis
cd redis
Put the prepared redis.conf into the reids directory
mkdir data
Docker download, install and run redis
Download the 5.0.5 version of redis
docker pull redis:5.0.5
docker images
Start redis
docker run -d -p 6379:6379 -v /usr/redis/redis.conf:/etc/redis/redis.conf -v /usr/redis/data:/data --name myredis redis:5.0.5 redis-server /etc/redis/redis.conf
Note: redis-server /etc/redis/redis.conf: specify the command executed when the container starts
If you don’t understand other commands, see my blog post about operating the container-->
Pit Three:
The container is created successfully, but it cannot run
Troubleshoot issues:
Look at the running log of redis
docker logs myredis
Error:
chown: changing ownership of '.': Permission denied
Insufficient permissions, the problem is found
solution:
Delete the redis container first
docker rm myredis
Add --privileged=true command
docker run -d -p 6379:6379 --privileged=true -v /usr/redis/redis.conf:/etc/redis/redis.conf -v /usr/redis/data:/data --name myredis redis:5.0.5 redis-server /etc/redis/redis.conf
Enter the container
docker exec -it myredis /bin/bash
Execute redis-cli to connect to redis
Prompt no permission, indicating that our redis.conf configuration has taken effect
Enter the verification password:
Under the test, OK
supplement:
Redis can be connected directly outside the container
docker exec -it myredis redis-cli
If you have encountered other pits, you can also leave a message to express, give someone a rose, leave a fragrance in your hand