gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:44:30 25 4
gpt4 key购买 nike

如何获取 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 .

关于Jelastic - 如何将环境变量获取到 Docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51135703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com