Community discussions

MikroTik App
aidanonym
刚刚加入了
Topic Author
Posts: 3
加入: Mon Sep 08, 2014 7:39 am

Container environment variable passing not working? (7.6/x86)

Sat Oct 29, 2022 1:05 pm

Hi,

I've been playing with RouterOS/x86 containers using Hyper-V, but I have not been able to get environment variables passing properly as per the example pihole youtube video. Apologies if there's something simple I'm missing, but I'm not seeing it. My plan was to experiment with ROS/x86 version before shifting to ARM.

This set of steps will reproduce the problem. I'm expecting the shell envrionment variables $FOO and $BAR to be set inside the container, but they are not.
Code:Select all
/container config set registry-url=https://registry-1.docker.io tmpdir=containers/pull /container envs add name=ubuntu_env key=FOO value=bar add name=ubuntu_env key=BAR value=baz /container/add remote-image=ubuntu:bionic interface=veth1 root-dir=container/ubuntu logging=yes envlist=ubuntu_env cmd="tail -f /dev/null" # wait for download and extract, then /container/start number=0 # wait for container to start, then /container/shell number=0 # "env" command shows shell environment variables are not set from ubuntu_env

Thanks in advance,
- aidan

Version info:
Code:Select all
[admin@ROS-x86] /container> /system/resource/print uptime: 1h17m21s version: 7.6 (stable) build-time: Oct/17/2022 10:55:40 factory-software: 7.1 free-memory: 331.8MiB total-memory: 960.0MiB cpu: Intel(R) cpu-count: 1 cpu-frequency: 4708MHz cpu-load: 0% free-hdd-space: 1846.9MiB total-hdd-space: 1934.1MiB write-sect-since-reboot: 1542112 write-sect-total: 1542112 architecture-name: x86_64 board-name: x86 platform: MikroTik
Top
aidanonym
刚刚加入了
Topic Author
Posts: 3
加入: Mon Sep 08, 2014 7:39 am

Re: Container environment variable passing not working? (7.6/x86)Topic is solved

Sun Nov 06, 2022 12:55 am

Environment variables passed in areonly set for the CMD that runs inside the containerin the Mikrotik environment. The shell has no access to these variables.

That the variablesarebeing set can be validated by settingcmd=envand checking the log file:
Code:Select all
/container/add remote-image=ubuntu:bionic interface=veth1 root-dir=container/ubuntu logging=yes envlist=ubuntu_env cmd="env" /container/start 1 /log/print ... oct/31 23:49:09 container,info,debug PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin oct/31 23:49:09 container,info,debug FOO=bar oct/31 23:49:09 container,info,debug BAR=baz


This behaviour is different on my Ubuntu Linux docker environment:
Code:Select all
$ docker run -d -e FOO=bar ubuntu "tail -f /dev/null" $ docker exec -it 2b93a49adca2 bash root@2b93a49adca2:/# env HOSTNAME=2b93a49adca2 PWD=/ FOO=bar HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ...
Top
CTSsean
newbie
Posts: 48
加入: Fri Sep 15, 2017 12:56 pm

Re: Container environment variable passing not working? (7.6/x86)

Fri Dec 16, 2022 7:16 pm

aidanonym,

I tried your recommendation when I check the log, I get this...
Code:Select all
/container /container add cmd=env envlist=ZTnetwork1 interface=veth1-ZT logging=yes start-on-boot=yes /container envs add key=NETWORK_ID name=ZTnetwork1 value=1234
Code:Select all
/log/print 17:13:16 container,info,debug r=> Configuring networks to join 17:13:16 container,info,debug r=> Joining networks: [env] 17:13:16 container,info,debug r===> Configuring join: [env] 17:13:16 container,info,debug r=> Starting ZeroTier 17:13:16 container,info,debug r=> Writing healthcheck for networks: [env]

I don't see the variable being set. Any suggestions?
Top

Who is online

Users browsing this forum: No registered users and 0 guests