解决docker运行redis报错:Fatal error, can‘t open config file /etc/redis/redis.conf以及启动redis后自动退出容器

这篇具有很好参考价值的文章主要介绍了解决docker运行redis报错:Fatal error, can‘t open config file /etc/redis/redis.conf以及启动redis后自动退出容器。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

现象如下:

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

 看了报错是权限问题,然后发现redis1.conf的权限果然不大对,

所以运行 chmod o+r 添加权限

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

但是启动后容器自动退出:

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

然后把redis-server改成绝对路径/usr/local/bin/redis-server

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

 此时就能发现报错真正的原因:是原始redis.conf配置文件内容的问题,而不是文件本身挂载的问题。 这里提示的其实就是容器内部没有/var/lib/redis这个路径

然后创建一个docker 存储卷,并挂载给/var/lib/redis

docker volume create myvolume

docker run --name xxxx  -v myvolume:/var/lib/redis xxxxxx

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

但是容器还是自动退出了:

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

 最后发现是redis配置文件中的daemonize yes选项在作怪,把它注释掉或者设成no

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

然后容器终于不再自动退出了可以正常启动了, 但是又报错

Failed opening the RDB file dump.rdb (in server root dir /var/lib/redis) for saving: Permission denied

 看起来还是权限问题:

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

这个错误表明 Redis 在持久化数据时无法打开 RDB 文件进行保存时,缺少写入权限。这通常是由于挂载的存储卷myvolume的权限问题导致的。

经过测试发现:给存储卷挂载时加:rw参数也是无效的

解决办法是:在宿主机redis配置文件所在的目录,创建一个tmp目录,然后给777权限,

然后把这个目录挂载给容器/var/lib/redis路径

mkdir tmp

chmod 777 tmp

docker run --name xxxx  -v `pwd`/tmp:/var/lib/redis xxxxx文章来源地址https://www.toymoban.com/news/detail-764145.html

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

需要注意一点:

redis.conf里面不要有logfile配置选项,否则docker logs 就没有日志输出了

 fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器

fatal error, can't open config file '/etc/redis/redis.conf': permission deni,docker,redis,容器 

总结一下:

解决docker运行redis报错:Fatal error, can't open config file /etc/redis/redis.conf以及启动redis后自动退出容器问题的解决办法:

1.  被挂载的redis.conf配置文件必须有足够的权限,能被root用户以外的用户所读取, 也就是能被docker容器内部读取

2.  redis.conf配置文件一定不能有daemonize yes选项,这也是redis容器自动退出的关键原因。

3. 需要从宿主机路径从外部挂载到容器内部路径/var/lib/redis, 否则会报错:Can't chdir to '/var/lib/redis': No such file or directory

4. 如果启用了redis持久化,  那么 容器内部路径/var/lib/redis也是需要读写权限的

 解决办法:在宿主机redis配置文件所在的目录,创建一个tmp目录,然后给777权限,

然后把这个目录挂载给容器/var/lib/redis路径

mkdir tmp

chmod 777 tmp

docker run --name xxxx  -v `pwd`/tmp:/var/lib/redis xxxxx

到了这里,关于解决docker运行redis报错:Fatal error, can‘t open config file /etc/redis/redis.conf以及启动redis后自动退出容器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • PyCharm 本地终端用不了报错can‘t open local...(已解决)

    今天打开pycharm ,发现终端用不了,一直显示 can\\\'t   open  local,具体报错情况如下:   在查阅资料后,我 先是在 设置了powershell路径,未解决 C:WindowsSystem32WindowsPowerShellv1.0powershell.exe  其次,又尝试了一种方法, 设置cmd路径,还是未解决 环境变量Path中添加了  Powershel

    2024年02月02日
    浏览(71)
  • 【Python终端报错】“python.exe: can‘t open file”【及解决方法】

    一、问题描述 如下图,在PyCharm中使用自带的Python终端运行源代码文件时,提示出错: D:Program FilesPython3.10.0python.exe: can’t open file ‘D:DesktopPython Security Chapter 4Whois’: [Errno 2] No such file or directory 翻译:python.exe找不到文件\\\"Whois\\\" 使用的命令为: 报错截图如下: 二、解决方法

    2024年02月02日
    浏览(32)
  • 【HBuilderX】打开运行到微信小程序报错,Error: Fail to open IDE

    一、问题: 二、分析: AppID没有权限 三、解决: 【微信小程序官网】https://mp.weixin.qq.com/ 【法1】 让管理员拉你进项目成员 【法2】 去除 ,打包时再加上 【法三】 换成自己的AppID

    2024年02月14日
    浏览(35)
  • 运行代码报错:FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

    一、背景         进公司拉取项目代码,npm install拉取依赖后,运行控制台报错:FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 二、原因分析         JavaScript heap out of memory说的是 JavaScript 运行内存不足,其实就是Node运行时内存不足。Node 中通过script使用

    2024年02月06日
    浏览(36)
  • Add Python Interpreter 报错 Error code:2. XX can‘t open file XX [Errno 2] No such file or directory

    刚下载Anaconda3,用conda create -n spytorch python=3.9命令创建了一个名为 spytorch 的虚拟环境;然后又下载了pycharm,结果往pycharm里配置时报错!下面是我踩坑的过程以及解决方法。 打开pycharm,选择新建项目。  进入Add Python Interpreter界面,找到Anaconda3envsspytorch下的python.exe文件  然

    2024年02月13日
    浏览(35)
  • 报错:Parsing error: No Babel config file detected...的解决方案

    报错:Parsing error: No Babel config file detected for E:前端学习资料9.vue基础classday03\\02-源代码\\01-componentvue.config.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. 报错方法解决 vue.config.js文件或babel.config.js文件或src中APP.vue开头有 红色

    2023年04月22日
    浏览(37)
  • 在docker中运行 pip 报错 Can‘t start new thread

    stackoverflow his is because the default seccomp profile of Docker 20.10.9 is not adjusted to support the clone() syscall wrapper of glibc 2.34 adopted in Ubuntu 21.10 and Fedora 35. 由于docker 版本与最新版 python 容器冲突导致 以下三种方式都可以解决 升级Docker 到 23.0.0 以上版本 修改python 镜像带有bullseye,例如 pytho

    2024年04月15日
    浏览(31)
  • 【已解决】vue报错:Parsing error: No Babel config file detected for...

    Vue项目报错:Parsing error: No Babel config file detected… 解决方法:在 package.json 里面添加 \\\"requireConfigFile\\\": false 即可。

    2024年02月15日
    浏览(34)
  • “/etc/ssh/sshd_config“ E212: Can‘t open file for writing

    错误信息 E212: Can\\\'t open file for writing 通常意味着你在尝试编辑文件时没有足够的权限,或者文件所在的目录不存在。在你的情况下,这是因为 /etc/ssh/sshd_config 是一个受保护的系统文件,通常只能由超级用户(root)编辑。 要解决这个问题,你需要以超级用户权限编辑该文件。

    2024年02月03日
    浏览(37)
  • Maven报错error in opening zip file解决方法

    试了改maven版本,改镜像地址,删除仓库下载的相关jar具体文件,都没解决,最后是还是删除仓库相关jar文件后Reimport才解决的, 但删除路径从仓库下的一级目录开始删除 ,比如H:softwareapache-maven-3.3.9-binlocalRepositoryorgapachepoipoi-ooxml4.1.2poi-ooxml-4.1.2.jar的报错,直接删除o

    2024年02月11日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包