Technical work, should be praised and then see, form a habitCopy the code

Docker use tutorial related series of directories


Get the redis. Conf

Redis official website: redis. IO /

Go to the official website, download the specified redis version, and decompress it to obtain redis.conf

Version 5.0.5 is used here

 

download.redis.io/releases/

Select the version you want

Unzip to get redis. Conf

Pit one:

The redis version obtained by the official website should be consistent with the redis version installed by the docker. Different versions of redis configuration files may have differences.

Modify the redis.conf configuration file

Enable Redis validation requirePass 123456

Allow redis to connect externally

#bind 127.0.0.1 to comment outCopy the code

Enable Redis data persistence

appendonly yes
Copy the code

Pit 2:

This configuration conflicts with the -d parameter in dcoker run, causing the container to fail to start

Daemonize yes commentsCopy the code

Create the redis directory

cd /usr
mkdir redis
Copy the code

cd redis 
Copy the code

Put the prepared redis.conf into the reids directory

mkdir data
Copy the code

Docker download install run Redis

Download redis version 5.0.5

Docker pull redis: 5.0.5Copy the code

docker images
Copy the code

Start the 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. ConfCopy the code

Note: redis-server /etc/redis/redis.conf: specifies the command to be executed when the container is started

Other commands do not understand, see my operation container blog –>

Pit 3:

The container was created, but failed to run

Troubleshooting problems:

Look at the Redis run log

docker logs myredis
Copy the code

Error:

chown: changing ownership of '.': Permission denied
Copy the code

Insufficient access. Problem found

Solution:

Delete the Redis container first

docker rm myredis
Copy the code

 

Added the — 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
Copy the code

Into the container

docker exec -it myredis /bin/bash
Copy the code

Run redis cli to connect to redis

If no permission is displayed, our redis.conf configuration is effective

Enter the authentication password:

Test it. OK

Supplement:

Redis can be connected directly outside the container

docker exec -it myredis redis-cli
Copy the code

If you also encounter other pits, you can also leave a message to express, give a rose, hand left lingering fragrance