是否可以在docker env_file中评估shell命令(在主机上执行)?

时间:2021-11-20 23:23:58

I run a docker container with docker run --env-file envfile image. envfile contains environment variables like LISTEN=localhost:12345, SSH_USER=jannis, etc.

我使用docker run --env-file envfile image运行一个docker容器。 envfile包含环境变量,如LISTEN = localhost:12345,SSH_USER = jannis等。

I tried adding a variable as follows: SSH_PRIVATE_KEY=`cat ~/.ssh/id_rsa`. I expected Docker to execute the command in $() on the host machine and set the variable to its output; however, Docker just set the variable literally. Is there a way to do this?

我尝试添加如下变量:SSH_PRIVATE_KEY =`cat~ / .ssh / id_rsa`。我希望Docker在主机上的$()中执行命令,并将变量设置为其输出;但是,Docker只是按字面设置变量。有没有办法做到这一点?

1 个解决方案

#1


0  

While writing this, I figured I can just let the executing shell do the work for me and pass --env SSH_PRIVATE_KEY=`cat ~/.ssh/id_rsa`.

在写这篇文章时,我想我可以让执行的shell为我工作并传递--env SSH_PRIVATE_KEY =`cat~ / .ssh / id_rsa`。

#1


0  

While writing this, I figured I can just let the executing shell do the work for me and pass --env SSH_PRIVATE_KEY=`cat ~/.ssh/id_rsa`.

在写这篇文章时,我想我可以让执行的shell为我工作并传递--env SSH_PRIVATE_KEY =`cat~ / .ssh / id_rsa`。