Docker 和 Rails: 无法访问日志文件

Docker and Rails: unable to access log file

当我启动 Rails 开发服务器(或 运行 测试)时,出现以下错误:

Rails Error: Unable to access log file. Please ensure that /usr/src/app/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /usr/src/app/log/development.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

即使在我 chmod -R 777 log 之后这个问题仍然存在。

我有我的应用程序 Dockerized 运行ning Alpine Linux。

导致此问题的原因可能是什么?

原来问题是因为我的 log 目录被挂载为 PostgreSQL 日志目录。

services:
  postgres:
    image: postgres:12.3-alpine
    mem_limit: 64m
    volumes:
      - ./log:/root/log:cached # <-- this line was the culprit
      - postgresql:/var/lib/postgresql/data:delegated
    ports:
      - "127.0.0.1:5432:5432"
    environment:
      PSQL_HISTFILE: /root/log/.psql_history
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 2s
      retries: 10
    logging:
      driver: none

我在 this GitHub issue 中更详细地描述了问题。