rancher-desktop
rancher-desktop copied to clipboard
nerdctl - environment variables not passed from host to container (-e)
Rancher Desktop Version
0.7.1
Rancher Desktop K8s Version
1.23.1
What operating system are you using?
macOS
Operating System / Build Version
macOS Big Sur 11.6.2
What CPU architecture are you using?
x64
Linux only: what package format did you use to install Rancher Desktop?
No response
Windows User Only
No response
Actual Behavior
When running a container with nerdctl, the environment variables are not passed to the container unless the value is explicitly defied in the run command.
nerdctl run -ti -e FOO=bar alpine env
- Will print the FOO variable
% export BAR=foo % nerdctl run -ti -e BAR alpine env
- Will not print the BAR variable even though it is being set on the host.
I have tried on debian as well and received the same result.
Steps to Reproduce
% export BAR=foo % nerdctl run -ti -e BAR -e FOO=bar alpine env
Result
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FOO=bar TERM=xterm HOME=/root
Expected Behavior
The expected behavior is that the env set on the host (BAR) would be passed to the container by specifying "-e BAR" in the run command.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin BAR=foo FOO=bar TERM=xterm HOME=/root
Additional Information
Possibly related to https://github.com/rancher-sandbox/rancher-desktop/issues/1267 but the main focus on that issue is related to proxies.
Just replicated the issue and it seems similar to https://github.com/lima-vm/lima/issues/412
Using containerd
:
❯ nerdctl run -it --env BAR --env FOO=bar alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FOO=bar
TERM=xterm
HOME=/root
❯ nerdctl run -it --env BAR --env FOO=bar alpine env
❯ export VERTO=test
❯ nerdctl run -it --env VERTO --env FOO=bar alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FOO=bar
TERM=xterm
HOME=/root
❯ nerdctl run -it --env $VERTO --env FOO=bar alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FOO=bar
TERM=xterm
HOME=/root
Using moby (dockerd) container runtime, works as expected:
❯ docker run -it --env BAR --env FOO=bar alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=827ccd1f8a61
TERM=xterm
BAR=foo
FOO=bar
HOME=/root
RD version: 1.0.0-beta1
OS: macOS Monterey 12.1 - amd64
This may be fixed when Rancher Desktop ships with nerdctl >= 1.1.0:
https://github.com/containerd/nerdctl/pull/1524
@bhavanki That is a different issue. The problem for Rancher Desktop is that nerdctl
has to run inside the VM to have access to the image layer storage. That means it doesn't see the environment variables defined in the shell on macOS.
The nerdctl
issue would be referring to the VM as the host, as opposed to the container.