当在“只读”文件系统上运行 Symfony 5 并预先生成缓存时,一切似乎都正常。但有各种日志条目,如下所示:
15:29:11 WARNING [cache] Failed to save key "%5BApp%5CEntity%5CAddress%5C%24GEDMO_TIMESTAMPABLE_CLASSMETADATA%5D%5B1%5D" of type array: fopen(/code/var/cache/prod/pools/VPOqRtOijV/82b6c3d711e9): failed to open stream: Permission denied ["key" => "%5BApp%5CEntity%5CAddress%5C%24GEDMO_TIMESTAMPABLE_CLASSMETADATA%5D%5B1%5D","exception" => ErrorException { …},"cache-adapter" => "Symfony\Component\Cache\Adapter\PhpFilesAdapter"]
15:29:11 WARNING [cache] Failed to save key "App__Entity__Address__CLASSMETADATA__" of type Doctrine\ORM\Mapping\ClassMetadata: fopen(/code/var/cache/prod/pools/VPOqRtOijV/82b6c3d711e9): failed to open stream: Permission denied ["key" => "App__Entity__Address__CLASSMETADATA__","exception" => ErrorException { …},"cache-adapter" => "Symfony\Component\Cache\Adapter\PhpFilesAdapter"]
缓存是在 Dockerfile 中预先生成的:
ARG APP_ENV=prod
RUN bin/console cache:warmup
使用只读
var/cache 目录运行 Symfony 还需要什么吗?
目录设置 ACL,如官方 Symfony 文档中所述,并通过手动执行包含以下内容的健康检查后脚本:
#!/bin/sh
set -eu
HTTP_SVC_USER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1) \
&& setfacl -dR -m u:"$HTTP_SVC_USER":rwX -m u:$(whoami):rwX var
我的协议如下:
docker run my-container
连接到您的容器:
docker exec -it my-container bash
HTTP_SVC_USER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1) \ && setfacl -dR -m u:"$HTTP_SVC_USER":rwX -m u:$(whoami):rwX var