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

Jelastic - how to get the environment variables to a Docker container

如何让 environment placeholders 显示在 Docker 容器中?

文档似乎并没有完全清楚地说明可以在哪里使用它们。我试图将它们设置在节点环境中,如添加到此问题的 JPS 文件中所示。

例如,它在 environment options

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

启动环境后,占位符仍与 JPS 文件中显示的一样,不会被实际值替换。

结果

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

-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}"
    }
}

在创建环境的过程中提到的占位符没有初始化,不能使用。 您可以使用方法AddContainerEnvVars。 在你的情况下,它会像 this.