当从 docker (v20.10.22) 中的 ubuntu 实例 (5.15.0-60-generic) 向 Symfony (v6.1.12, php8.2.1) 应用程序的运行 api 平台接口发送请求时,与此类似:
http://localhost/api/posts?limit=20
我一直在检索服务器错误 500 和错误消息,指出“您的 hydrator 目录必须是可写的”。
我在 Ubuntu 22.04.1 LTS 上运行的 docker 容器中收到针对 api 平台的每个请求的错误消息。
如果我在 MACOS 环境中运行完全相同的 docker 容器设置,我不会收到此错误消息并且一切正常。
因此,我假设发生此错误是因为学说试图将查询结果缓存在不允许写入的 docker 容器内的目录中。
我已经检查了 var/cache 的文件权限并且 0777ed 它们没有成功。
有人可以通过指定学说在水合作用过程中物理缓存结果的位置来帮助我,这样我就可以手动启用该目录的写访问权限,或者建议另一种解决方法来为在 docker 容器中运行的学说启用写权限。
为了更好的再现性,我在这里转储了我的作曲家依赖项的内容:
composer show | grep -e "symfony\|Doctrine"
doctrine/cache 2.2.0 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers suc...
doctrine/collections 1.8.0 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common 3.4.3 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine p...
doctrine/data-fixtures 1.6.3 Data Fixtures for all Doctrine Object Managers
doctrine/doctrine-bundle 2.8.3 Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle 3.4.2 Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.2.2 Symfony DoctrineMigrationsBundle
doctrine/event-manager 1.2.0 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Do...
doctrine/inflector 2.0.6 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/...
doctrine/lexer 2.1.0 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations 3.6.0 PHP Doctrine Migrations project offer additional functionality on top of the database abstraction lay...
doctrine/mongodb-odm 2.4.3 PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to...
doctrine/mongodb-odm-bundle 4.5.2 Symfony Doctrine MongoDB Bundle
doctrine/persistence 3.1.4 The Doctrine Persistence project is a set of shared interfaces and functionality that the different D...
friendsofsymfony/elastica-bundle v6.2.0 Elasticsearch PHP integration for your Symfony project using Elastica
gedmo/doctrine-extensions v3.11.1 Doctrine behavioral extensions
symfony/apache-pack v1.0.1 A pack for Apache support in Symfony
symfony/asset v5.4.19 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and ima...
symfony/browser-kit v6.2.5 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit for...
symfony/cache v6.2.5 Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts v3.2.0 Generic abstractions related to caching
symfony/config v6.2.5 Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console v6.2.5 Eases the creation of beautiful and testable command line interfaces
symfony/css-selector v6.2.5 Converts CSS selectors to XPath expressions
symfony/dependency-injection v6.1.12 Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts v3.2.0 A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge v5.4.19 Provides integration for Doctrine with various Symfony components
symfony/doctrine-messenger v6.2.5 Symfony Doctrine Messenger Bridge
symfony/dom-crawler v6.2.5 Eases DOM navigation for HTML and XML documents
symfony/dotenv v6.2.5 Registers environment variables from a .env file
symfony/error-handler v6.2.5 Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher v6.2.5 Provides tools that allow your application components to communicate with each other by dispatching e...
symfony/event-dispatcher-contracts v3.2.0 Generic abstractions related to dispatching event
symfony/expression-language v5.4.19 Provides an engine that can compile and evaluate expressions
symfony/filesystem v6.2.5 Provides basic utilities for the filesystem
symfony/finder v6.2.5 Finds files and directories via an intuitive fluent interface
symfony/flex v2.2.5 Composer plugin for Symfony
symfony/framework-bundle v6.0.19 Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client v6.2.6 Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts v3.2.0 Generic abstractions related to HTTP clients
symfony/http-foundation v6.2.6 Defines an object-oriented layer for the HTTP specification
symfony/http-kernel v6.1.12 Provides a structured process for converting a Request into a Response
symfony/mailer v6.1.11 Helps sending emails
symfony/maker-bundle v1.48.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can f...
symfony/messenger v6.2.5 Helps applications send and receive messages to/from other applications or via message queues
symfony/mime v6.1.11 Allows manipulating MIME messages
symfony/monolog-bridge v5.4.19 Provides integration for Monolog with various Symfony components
symfony/monolog-bundle v3.8.0 Symfony MonologBundle
symfony/options-resolver v6.2.5 Provides an improved replacement for the array_replace PHP function
symfony/password-hasher v6.2.5 Provides password hashing utilities
symfony/phpunit-bridge v6.2.5 Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme v1.27.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn v1.27.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.27.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring v1.27.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72 v1.27.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73 v1.27.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80 v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81 v1.27.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/property-access v5.4.19 Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info v5.4.19 Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge v5.4.19 Provides integration for ProxyManager with various Symfony components
symfony/routing v6.2.5 Maps an HTTP request to a set of configuration variables
symfony/security 2.0.6 Symfony Security Component
symfony/security-bundle v5.4.20 Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core v5.4.19 Symfony Security Component - Core Library
symfony/security-csrf v6.2.5 Symfony Security Component - CSRF Library
symfony/security-guard v5.4.19 Symfony Security Component - Guard
symfony/security-http v5.4.20 Symfony Security Component - HTTP Integration
symfony/serializer v5.4.19 Handles serializing and deserializing data structures, including object graphs, into array structures...
symfony/service-contracts v2.5.2 Generic abstractions related to writing services
symfony/stopwatch v6.2.5 Provides a way to profile code
symfony/string v6.2.5 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clust...
symfony/translation-contracts v3.2.0 Generic abstractions related to translation
symfony/twig-bridge v6.1.11 Provides integration for Twig with various Symfony components
symfony/twig-bundle v5.4.19 Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator v5.4.19 Provides tools to validate values
symfony/var-dumper v6.2.5 Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter v6.2.5 Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link v6.2.5 Manages links between resources
symfony/webpack-encore-bundle v1.16.1 Integration with your Symfony app & Webpack Encore!
symfony/yaml v6.2.5 Loads and dumps YAML files
按照此处的建议使用简单的 umask(0000):https://symfony.com/doc/current/setup/file_permissions.html#3-without-using-acl,可以解决此问题。
为什么只有在 ubuntu 环境中运行的 docker 容器才需要此修复的问题仍未得到解答。我认为容器的行为是 100% 相同的,无论它们是从哪个操作系统启动的,但情况似乎并非总是如此。