lov*_*ova 9 php environment-variables openshift docker openshift-origin
我想在我的 docker 容器中显示一个 env var。PHP 脚本如下所示:
<html>
<head>
<title>Show Use of environment variables</title>
</head>
<body>
<?php
print "env is: ".$_ENV["USER"]."\n";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我使用 OpenShift 来启动容器。PHP - 容器显示:
env is:
Run Code Online (Sandbox Code Playgroud)
现在我更改了容器的 dc 配置:
oc env dc/envar USER=Pieter
deploymentconfig "envar" updated
Run Code Online (Sandbox Code Playgroud)
当我访问容器时。USER 的环境变量是 Pieter
docker exec -it 44a0f446ae36 bash
bash-4.2$ echo $USER
Pieter
Run Code Online (Sandbox Code Playgroud)
但是我的脚本仍然显示:“ env is:”它没有填充变量。
改变
print "env is: ".$_ENV["USER"]."\n";
Run Code Online (Sandbox Code Playgroud)
到
print "env is: ".getenv("USER")."\n";
Run Code Online (Sandbox Code Playgroud)
.
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>
Run Code Online (Sandbox Code Playgroud)
# export USER=Sascha
# echo $USER
Sascha
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14240 次 |
| 最近记录: |