【问题标题】:How can i set an ENV variable in a Dockerfile the content from a .txt file? [duplicate]如何在 .txt 文件中的 Dockerfile 中设置 ENV 变量? [复制]
【发布时间】:2017-12-15 04:39:57
【问题描述】:

我正在尝试 Dockerize 一个 Node.js 应用程序,在创建 Dockerfile 时,我遇到了连接数据库的凭据存储在 .txt 文件中的问题。如何将 .txt 文件中的内容设置为我的 Dockerfile 中的 ENV 变量?

【问题讨论】:

  • 编写一个 shell 脚本来提取这些凭据并在 Dockerfile 中写入一些行,例如 ENV mypassword abc123?

标签: node.js docker environment-variables dockerfile


【解决方案1】:

您可以使用--env-file 命令行选项:

docker run --env-file ./env.list ubuntu bash

此文件应使用语法<variable>=value(设置 变量到给定值)或<variable>(从 本地环境),# 用于 cmets。

更多详情,see the documentation here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2014-04-23
    • 2021-08-19
    相关资源
    最近更新 更多