我正在尝试在 Docker 中运行一个多进程应用程序,其中 runit 作为 init 进程,但 runit 不会将环境变量传递给应用程序:
在 Dockerfile 中:
CMD ["runit"]
服务文件/etc/service/app/run
如下所示:
#!/bin/sh
exec 2>&1
echo "ENV_VAR=$ENV_VAR"
exec app
当我使用ENV_VAR
set 运行 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 将环境变量传递给服务/应用程序?