2016-02-18 1 views
3

Je souhaite afficher une variable var dans mon conteneur docker. Le script PHP ressemble à ceci:Variable d'environnement dans le conteneur PHP-docker

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

J'utilise OpenShift pour démarrer le conteneur. Le PHP - conteneur indique:

env is: 

Maintenant je changer la config en courant continu de mon conteneur:

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

Quand j'accéder au conteneur. Env var USER est Pieter

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

Mais mon script reste affiché: "env is:" Il ne remplit pas la variable.

+0

Que montre le journal? – Auzias

Répondre

-1

changement

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> 
/#