PHP-docker容器中的环境variables

我想在我的泊坞窗容器中显示一个env var。 PHP脚本如下所示:

<html> <head> <title>Show Use of environment variables</title> </head> <body> <?php print "env is: ".$_ENV["USER"]."\n"; ?> </body> </html> 

我使用OpenShift来启动容器。 PHP – 容器显示:

 env is: 

现在我更改我的容器的dcconfiguration:

 oc env dc/envar USER=Pieter deploymentconfig "envar" updated 

当我访问容器。 USER的env var是Pieter

 docker exec -it 44a0f446ae36 bash bash-4.2$ echo $USER Pieter 

但我的脚本仍然显示:“ env is: ”它不填写variables。

更改

 print "env is: ".$_ENV["USER"]."\n"; 

 print "env is: ".getenv("USER")."\n"; 

 /# cat test.php <html> <head> <title>Show Use of environment variables</title> </head> <body> <?php print "env via \$_ENV is: ".$_ENV["USER"]."\n"; print "env via getenv is: ".getenv("USER")."\n"; ?> </body> </html> / # / # export USER=Sascha / # echo $USER Sascha / # php test.php <html> <head> <title>Show Use of environment variables</title> </head> <body> PHP Notice: Array to string conversion in /test.php on line 7 PHP Notice: Undefined index: USER in /test.php on line 7 env via $_ENV is: env via getenv is: Sascha </body> </html> / #