我有一个symfony2应用程序。我们之前已经为开发设置了一个docker-compose堆栈,这就是为什么我们希望通过环境变量而不是parameters.yml来设置所有配置。
因此我从:
替换了我的parameters.yml的内容parameters:
locale: 'en'
secret: 'SOME_SECURITY_TOKEN'
...
为:
parameters:
locale: '%locale%'
secret: '%secret%'
...
我的docker-compose.yml
文件包含:
my_app:
hostname: my-app
build: .
dockerfile: Dockerfile.dev
ports:
- "9080:80"
- "9043:433"
environment:
LOCALE: en
SECRET: SOME_SECURITY_TOKEN
...
然而,在重建我的容器后,我得到了例外:
ParameterCircularReferenceException in ParameterBag.php line 209: Circular reference detected for parameter "secret" ("secret" > "secret").
1. in ParameterBag.php line 209
2. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
3. at ParameterBag->resolveValue('%secret%', array('secret' => true)) in ParameterBag.php line 214
4. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
5. at ParameterBag->resolveValue('%secret%', array()) in ParameterBag.php line 175
6. at ParameterBag->resolveValue(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null, 'csrf_protection' =>
null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null, 'trusted_proxies' => null,
'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array()) in ParameterBag.php line 175
7. at ParameterBag->resolveValue(array(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null,
'csrf_protection' => null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null,
'trusted_proxies' => null, 'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array('router' =>
array('resource' => '%kernel.root_dir%/config/routing_dev.yml', 'strict_requirements' => true), 'profiler' => array('only_exceptions' => false)))) in MergeExtensionConfigurationPass.php line 45
8. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
9. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 107
10. at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 589
11. at ContainerBuilder->compile() in bootstrap.php.cache line 2687
12. at Kernel->initializeContainer() in bootstrap.php.cache line 2465
13. at Kernel->boot() in bootstrap.php.cache line 2496
14. at Kernel->handle(object(Request)) in app_dev.php line 30
然而在我的容器中,我确实看到了env变量:
le-container:/var/www/my-app# env
SECRET=SOME_SECURITY_TOKEN
LOCALE=en
我做错了什么以及如何解决?
答案 0 :(得分:1)
出于某种原因,在我的环境变量中添加前缀修复了问题:
parameters:
locale: '%foo_locale%'
secret: '%foo_secret%'
当然,无论何时设置变量。我目前的工作理论是symfony不喜欢具有相同的参数名称和env变量,但我不确定。
答案 1 :(得分:0)
parameters:
locale: '%locale%'
secret: '%secret%'
无用的构造,区域设置和秘密已经是参数。只需删除此块。
答案 2 :(得分:0)
有一个使用external parameters的解决方案。使用“SYMFONY__”为变量添加前缀。在你的情况下,它将是:
my_app:
...
environment:
SYMFONY__APP__LOCALE: en
SYMFONY__APP__SECRET: SOME_SECURITY_TOKEN
...
在您的参数中,您可以按照以下方式调用它:
parameters:
locale: %app.locale%
secret: %app.secret%