Jelastic-如何将环境变量获取到Docker容器

时间:2018-07-02 11:58:29

标签: jelastic

如何让environment placeholders出现在Docker容器中?

文档似乎还不清楚在哪里可以使用它们。我试图像在添加到此问题的JPS文件中所示的那样,在节点env内设置它们。

例如,它在environment options

中将环境显示为env-2461411,并将其名称显示为Environment Test

启动环境后,占位符仍保持在JPS文件中显示的位置,而不用实际值替换。

结果

占位符似乎没有被替换,因此外壳不喜欢它所获得的环境:

-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution
-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution

预期结果

bash环境中显示的环境变量,例如

env_domain=env-2461411
env_name=Environment Test 

示例JPS文件

{
    "jpsType": "install",
    "jpsVersion": "1.4",
    "name": "Environment Test",
    "description":
    {
        "text": "Template for testing environment variables test",
        "short": "Environment variables test"
    },
    "logo": "https://raw.githubusercontent.com/jelastic-jps/start-stop-scheduler/master/images/logo.png",
    "homepage": "https://jelastic.com/",
    "categories":
    [
        "apps/testing"
    ],
    "success":
    {
        "text": "## Environment test is up and running\nOpen the Jelastic SSH gateway and locate the test-node, see its environment with `env`"
    },
    "nodes":
    [
        {
            "image": "debian",
            "extip": false,
            "count": 1,
            "cloudlets": 16,
            "fixedCloudlets": 1,
            "nodeType": "docker",
            "nodeGroup": "test",
            "displayName": "test-node",
            "volumes":
            [
                "/root"
            ],
            "env":
            {
                "env_appid": "${env.appid}",
                "env_domain": "${env.domain}",
                "env_url": "${env.url}",
                "env_displayname": "${env.displayName}",
                "env_envname": "${env.envName}",
                "env_name": "${env.name}",
                "env_shortdomain": "${env.shortdomain}"
            }
        }
    ],
    "onInstall":
    {
        "log": "${placeholders}"
    }
}

1 个答案:

答案 0 :(得分:1)

在环境创建过程中,提到的占位符未初始化,因此无法使用。 您可以使用方法AddContainerEnvVars。 就您而言,它就像this