将本地环境变量传递给docker

时间:2015-09-24 13:05:42

标签: docker dockerfile docker-compose

这可能是一般的码头工具问题,但我的用例是docker-compose:

我需要将我的机器的主机名作为环境变量传递给通过docker-compose创建的容器。该特定容器使用Dockerfile并在其中使用“cmd”标志。 “cmd”中的命令使用此环境变量。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

如果您可以重写Dockerfile以便在ENV instruction, issue 1136中包含主机名,那将会有效:

docker compose

如果这纯粹是一个运行时环境变量值,它应该包含在带有issue 14634: Builder - Build-time argument passing (e.g., HTTP_PROXY)的docker 1.9中:

与此同时,OP 208rishabh提到environment: HOST_HOSTNAME: issue 2091dnephin回答:

  

environment或env_file should both work

     

您可以将值保留为空白,它将获取当前环境中的值:

HOST_HOSTNAME=$(hostname) docker-compose up

允许:

let notificationSelectorShowAd: Selector = "showAd"

var showAdNotification = NSNotificationCenter
                         .defaultCenter()
                         .addObserver(self,  
                                      selector: notificationSelectorShowAd, 
                                      name: "GameStateOff", 
                                      object: nil)
相关问题