gpt4 book ai didi

docker - Docker容器中的Runit不会传递环境变量

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

我正在尝试在Docker中运行多进程应用程序,并将runit用作初始化进程,但runit不会将环境变量传递给该应用程序:

在Dockerfile中:

CMD ["runit"]

服务文件 /etc/service/app/run如下所示:
#!/bin/sh
exec 2>&1

echo "ENV_VAR=$ENV_VAR"
exec app

当我运行带有 ENV_VAR设置的docker容器时,该变量不会被runit传递给应用程序。输出:
# docker run --name container -e ENV_VAR=loremipsum -d IMAGE_NAME
# docker logs container
- runit: $Id: 25da3b86f7bed4038b8a039d2f8e8c9bbcf0822b $: booting.
- runit: warning: unable to open /dev/console: file does not exist
- runit: enter stage: /etc/runit/1
/etc/runit/1: 6: /etc/runit/1: /etc/init.d/rcS: not found
/etc/runit/1: 7: /etc/runit/1: /etc/init.d/rmnologin: not found
/etc/runit/1: 12: /etc/runit/1: /etc/init.d/rc: not found
- runit: warning: child failed: /etc/runit/1
- runit: leave stage: /etc/runit/1
- runit: enter stage: /etc/runit/2
ENV_VAR=
...
* app failed because ENV_VAR was not set correctly *

如何使Runit将环境变量传递给服务/应用程序?

最佳答案

你可以这样尝试

ENV MY_ENV_VAR $MY_ENV_VAR

要么

这里的例子
ARG var_name
ENV env_var_name=$var_name


docker build --build-arg var_name=${VARIABLE_NAME} (...)

关于docker - Docker容器中的Runit不会传递环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54089994/

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