Linux environment dockers install redis

1: the first step

docker pull redis

2: In the second step, the default password is empty, –name means to specify the container alias, and -d means to run in the background

docker run --name hdxredis -d -p 6379:6379  redis

3.1: Mount the configuration file of redis, and start the redis container as a configuration file

Create a folder for placing configuration files, the path of the folder is selected according to your own situation

mkdir -p /home/redis/myredis

3.2: Create a folder named data under the 3.1 folder

mkdir -p /home/redis/myredis/data

4: Start the container

docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis -v /home/redis/myredis/myredis.conf:/etc/redis/redis.conf -v /home/redis/myredis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 123456

Start command explanation

--restart=always 代表总是开机启动
--log-opt 代表日志方面
-p 6379:6379 代表将6379端口挂载出去
--name myredis 代表给容器取一个名字
-v /home/redis/myredis/myredis.conf:/etc/redis/redis.conf 代表将自己上传的配置文件和redis的配置文件挂载在一起
-v /home/redis/myredis/data:/data 将数据挂载在一起
-d redis 代表后台启动
redis-server /etc/redis/redis.conf 代表以配置文件启动redis,加载容器内的conf文件,因为文件挂载,最终找到上面自定义的配置文件
--appendonly yes 开启aof持久化
--requirepass 123456 设置密码,docker内部连接的话,此密码没有效,用于对外开放

Guess you like

Origin blog.csdn.net/qq_19891197/article/details/130851334