1. Download the Redis image
Docker pull redis: 5.0Copy the code
2. Create a data volume
#Create mount directory data and configuration file directories
mkdir -p /home/docker/redis/data /opt/docker/redis/conf
#Write the redis. Conf file
cd /home/docker/redis/conf
vim redis.conf
Copy the code
The content of the configuration file is as follows
#bind 127.0.0.1 // allow remote connections # password temporarily such requirepass 123456 port 33 appendonly yesCopy the code
For details about the redis configuration file, see the redis
Here is the website of redis: 5.0 version of redis. Conf example: raw.githubusercontent.com/antirez/red…
3. Start the redis
docker run --name redis -p 6379:6379 -v /home/docker/redis/data:/data -v / home/docker/redis/conf/redis. Conf: / etc/redis/redis conf - d redis: 5.0 / etc/redis/redis. ConfCopy the code
Resolution:
- –name redis The name of the container after startup is redis
- -d The container runs in the background and returns the container ID
- -p 6379:6379 Specifies the port mapping. The format is host port: container port
- – v/home/docker/redis/data: data/data volume mount, pay attention to is the absolute path, starting from the root directory.
- – v/home/docker/redis/conf/redis. Conf: / etc/redis/redis conf mount the redis configuration file
- /etc/redis/redis.conf Specifies that the container is started with the self-configured conf file
Start-up success
Docker exec -it redis-cliCopy the code
Enter the redis client, here the previous configuration file redis. Conf set the password of redis to 123456, so before the operation of the auth password to log in, finally use ping test.