Runit в контейнере Docker не передает переменные окружения
Я пытаюсь запустить многопроцессорное приложение в Docker с runit, служащим процессом init, но runit не передает переменные среды в приложение:
В Dockerfile:
CMD ["runit"]
Сервисный файл /etc/service/app/run
выглядит так:
#!/bin/sh
exec 2>&1
echo "ENV_VAR=$ENV_VAR"
exec app
Когда я запускаю Docker-контейнер с ENV_VAR
установить, переменная не передается в приложение с помощью 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 передать переменную окружения в сервис / приложение?
1 ответ
Ты можешь попробовать этот путь
ENV MY_ENV_VAR $MY_ENV_VAR
или же
пример здесь
ARG var_name
ENV env_var_name=$var_name
а также
docker build --build-arg var_name=${VARIABLE_NAME} (...)
I came by your question while working on similar setup and found out it was working for me so as you can see in my example below that you have the ability to call the environment variable directly.
Here is the example I have tested:
Script 1
# This is the run script that will be used for this dummy service
$ cat stackru-question/run
#!/bin/sh
exec 2>&1
exec echo "$Q_NUM"
Script 2
# This is the run script that will be used for this dummy service
$ cat stackru-question/run
#!/bin/sh
exec 2>&1
NUMBER=$Q_NUM
exec echo "$NUMBER"
I have used an image called https://hub.docker.com/r/dockage/alpine-runit/ for testing so feel free to use your own runit
installation still applies.
Note: I Have tested both the default CMD
that comes with this image and the runit
command to reproduce your example and both worked as expected as you can see it prints the question number as we wanted.
$ docker run -it --rm -v "$PWD:/service/" \
-e Q_NUM=54089994 dockage/alpine-runit:latest runit
- runit: $Id: 25da3b86f7bed4038b8a039d2f8e8c9bbcf0822b $: booting.
- runit: enter stage: /etc/runit/1
- runit: leave stage: /etc/runit/1
- runit: enter stage: /etc/runit/2
54089994
54089994
54089994
54089994