为什么不能通过docker-compose访问磁盘?

根据docker文档,我使用redis尝试了一个非常简单的python应用程序的第一个testing。 这之后崩溃,因为redis不能坚持。 我不知道为什么。 你可以在这里find公共回购: Github回购

我目前的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映像没有做任何事情。

这是一个权限错误,通过docker exec -it redis_container_name bashlogin到redis容器,并确保它对/data具有写权限。

它可能不会,你可以用几种方法修复:使用docker volume来代替bind-mount主机,或者通过在容器中拥有与所有者相匹配的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创build一个新的权限。

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

一旦我使用docker文件的版本2,它工作正常。