为什么redis无法访问docker-compose中的磁盘?

Den*_*ene 13 redis docker docker-compose

根据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
Run Code Online (Sandbox Code Playgroud)

编辑:这是日志的摘录:

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

有趣的是,我对redis图像没有任何作用.

Lou*_*ann 26

这是一个权限错误,通过redis容器登录docker exec -it redis_container_name bash并确保它具有写入权限/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
Run Code Online (Sandbox Code Playgroud)

如果你打算坚持数据.

由于您的data文件夹设置了错误的权限,因此请先删除它并让docker-compose创建一个新的权限.