当前位置:网站首页>docker安装redis并以配置文件方式启动
docker安装redis并以配置文件方式启动
2022-07-23 15:14:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
——————————-
更新 最近发现服务器被挖矿病毒入侵了 很有可能是因为redis没有设置密码的原因!
——————————-
1.获取redis镜像
docker pull redis
指定版本号:
docker pull redis:4.0.9
不加版本号默认获取最新版本,也可以使用 docker search redis 查看镜像来源
2.查看本地镜像
docker images
3.然后启动容器,做映射
①创建配置文件目录存放redis.conf,文件从官网下载。
②创建文件夹,新建配置文件贴入从官网下载的配置文件并修改
mkdir /usr/local/docker
vi /usr/local/docker/redis.conf
③修改启动默认配置(从上至下依次):
bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
protected-mode no #默认yes,开启保护模式,限制为本地访问
daemonize no#默认no,改为yes意为以守护进程方式启动,可后台运行,除非kill进程,改为yes会使配置文件方式启动redis失败
databases 16 #数据库个数(可选),我修改了这个只是查看是否生效。。
dir ./ #输入本地redis数据库存放文件夹(可选)
appendonly yes #redis持久化(可选)
4.docker启动redis命令
docker run -p 6379:6379 --name myredis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes命令解释说明:
-p 6379:6379 端口映射:前表示主机部分,:后表示容器部分。
–name myredis 指定该容器名称,查看和进行操作都比较方便。
-v 挂载目录,规则与端口映射相同。
为什么需要挂载目录:个人认为docker是个沙箱隔离级别的容器,这个是它的特点及安全机制,不能随便访问外部(主机)资源目录,所以需要这个挂载目录机制。
-d redis 表示后台启动redis
redis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件,最终找到的是挂载的目录/usr/local/docker/redis.conf
–appendonly yes 开启redis 持久化
5.查看是否运行成功
docker ps 查看运行的容器
docker logs myredis/27ddba64faa6 (容器名称/id)
docker基本命令:
查看所有镜像 docker images
删除镜像(会提示先停止使用中的容器) docker rmi 镜像name/镜像id
查看所有容器 docker ps -a
查看容器运行日志 docker logs 容器名称/容器id
停止容器运行 docker stop 容器name/容器id
终止容器后运行 docker start 容器name/容器id
容器重启 docker restart 容器name/容器id
删除容器 docker rm 容器name/容器id
最后给大家推荐一款开源客户端连接工具
https://github.com/qishibo/AnotherRedisDesktopManager/releases
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126567.html原文链接:https://javaforall.cn
边栏推荐
- Literature learning (part100) -- an introduction to autoencoders
- mysql字段修改
- TwinCAT 3 first run error 4115
- JDBC program example using Preparedstatement
- Single cell thesis record (part19) -- a comprehensive comparison on cell type composition information for St data
- TP & smart use diary
- The use method of quota command is expanded in detail, and the carrying method of quota command in RHEL 7! Disk capacity quota!
- Date formatting
- Element content must consist of character data or tags with correct format
- 为啥一问 JVM 就 懵B ???
猜你喜欢

ride the wind and waves! Digital transformation in the era of financial technology

你真的了解Redis的持久化机制吗?

深入理解机械系统的模态与振动

Solutions to sap Hana database backup failure

As a background developer, you must know two kinds of filters

Thread pool, who am I? Where am I?

isEmpty 和 isBlank 的用法区别,至少一半的人答不上来...

el-input使用

rust中的静态分发和动态分发

Interviewer: what is the possible reason for the slow query of MySQL database besides the index problem?
随机推荐
A series of specifications of oneplus 10t were disclosed before the product was released
el-input使用
Research and implementation of network multi exit design based on policy routing deployment
Leetcode skimming: dynamic planning 04 (different paths)
爱可可AI前沿推介(7.23)
Rust中的dyn关键字
sublime text使用技巧
作为一名后台开发人员,你必须知道的两种过滤器
phpstrom快捷键
Visual computer room management
The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
基于C语言开发的控制台计算器
MySQL executes alter table XX add column with duplicate entry error
Console calculator developed based on C language
Create a flow using flow builder in kotlin
活动报名:如何零基础快速上手开源的 Tapdata Live Data Platform?
Implementation of deep copy deepclone
[pytorch] basic use 7. GPU allocation
curl get&post
Why do you get confused when you ask JVM???