【问题标题】:Why can't redis access the disk in docker-compose?为什么redis不能访问docker-compose中的磁盘?
【发布时间】:2016-01-26 20:05:39
【问题描述】:

根据 docker 文档,我尝试了一个非常简单的带有 redis 的 python 应用程序的第一次测试。这会在一段时间后崩溃,因为 redis 无法持久化。我不知道为什么。你可以在这里找到公共回购:Github repo

我当前的 docker-compose.yml 是:

web:
  build: .
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis:latest
  volumes:
  - ./data:/data

编辑:这是日志的摘录:

1:M 09 Feb 10:51:15.130 # Background saving error
1:M 09 Feb 10:51:21.072 * 100 changes in 300 seconds. Saving...
1:M 09 Feb 10:51:21.073 * Background saving started by pid 345
345:C 09 Feb 10:51:21.074 # Failed opening .rdb for saving: Permission denied
1:M 09 Feb 10:51:21.173 # Background saving error
1:M 09 Feb 10:51:27.011 * 100 changes in 300 seconds. Saving...
1:M 09 Feb 10:51:27.011 * Background saving started by pid 346
346:C 09 Feb 10:51:27.013 # Failed opening .rdb for saving: Permission denied

Edit2:这是 Redis 在 python 中抛出的完整错误:

MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error

有趣的是,我没有对 redis 图像做任何事情。

【问题讨论】:

  • 它一定是你机器里的东西,我已经测试了你的 .yml 文件,它对我有用
  • 你确定它崩溃是因为 Redis 不能持久化吗?这不是 Redis 的行为方式
  • 你可以通过docker logs --follow <container_name or container_id>查看你的redis容器的日志。你可以在这里查看并发布吗?
  • 您好,我已经添加了日志的摘录。

标签: docker redis docker-compose


【解决方案1】:

是权限错误,通过docker exec -it redis_container_name bash登录redis容器,确保对/data有写权限。

它可能没有,您可以通过多种方式修复它:使用 docker volume 而不是绑定挂载主机,或者尝试通过将 uid/gid 与容器中的所有者匹配来修复主机的权限。

另外,如 docker hub 页面所述,您应该将 redis 的命令设置为:

web:
  build: .
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis:latest
  command: redis-server --appendonly yes
  volumes:
  - ./data:/data

如果您打算持久化数据。

由于您的 data 文件夹设置了错误的权限,请先将其删除,然后让 docker-compose 新建一个。

【讨论】:

  • 你可以分叉回购,更新你认为应该是什么并向我发送拉取请求?我尝试了一些东西,但是因为我对 docker 非常陌生,所以我真的不明白。对不起。
【解决方案2】:

我已经用工作版本更新了我的 repo,标记为 0.2

一旦我使用了 docker 文件的第 2 版,它就可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2022-08-02
    • 2021-09-26
    相关资源
    最近更新 更多