Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

environment variables of current shell can't be passed to container via nerdctl run '-e' option #1487

Closed
sixwaaaay opened this issue Nov 8, 2022 · 4 comments · Fixed by #1524
Labels
bug Something isn't working

Comments

@sixwaaaay
Copy link

Description

behaivors as follow will print 10

export X=10
docker run -e X alpine printenv X

however, nothing will be printed when I use nerdctl

export X=10
nerdctl run -e X alpine printenv X

Steps to reproduce the issue

  1. set env var export X=10
  2. run a container with the env var and print it in container nerdctl run -e X alpine printenv X

Describe the results you received and expected

result: nothing
expected: print 10

What version of nerdctl are you using?

nerdctl version:

Client:
Version: v1.0.0
OS/Arch: linux/amd64
Git commit: c00780a
buildctl:
Version: v0.10.5
GitCommit: bc26045116045516ff2427201abd299043eaf8f7

Server:
containerd:
Version: v1.6.9
GitCommit: 1c90a442489720eec95342e1789ee8a5e1b9536f
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d1

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

No response

Host information

OS information:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

@sixwaaaay sixwaaaay added the kind/unconfirmed-bug-claim Unconfirmed bug claim label Nov 8, 2022
@sixwaaaay sixwaaaay changed the title environment variables of current shell can't be passed to container via nerdctl run ''-e' option environment variables of current shell can't be passed to container via nerdctl run '-e' option Nov 8, 2022
@djdongjin
Copy link
Member

I tired this and noticed this might because the different behavior between docker and containerd:

Docker said an env without value (e.g., -e X vs -e X=10) means obtaining the value from shell: docker

Containerd said that means unsetting the value: nerdctl, containerd.

Though I'm not sure if this is expected containerd behavior defined in oci. cc: @AkihiroSuda

@djdongjin
Copy link
Member

@sixwaaaay btw, I think you can work around this by nerdctl run -e X=$X alpine printenv X

@AkihiroSuda AkihiroSuda added bug Something isn't working and removed kind/unconfirmed-bug-claim Unconfirmed bug claim labels Nov 8, 2022
@sixwaaaay
Copy link
Author

This command does not seem to work for passing environment variables with multi-line text
My attempt is to use base64 encoding to convert multi-line text into a base64 text without line breaks every 76 characters, then pass it to the container and decode it in the container.

export X=`cat file | base64 -w 0` # export X=`printenv X | base64 -w 0`
nerdctl run -e X=$X alpine printenv X | base64 -d

I think it seems a little troubling

@liubin
Copy link
Contributor

liubin commented Nov 18, 2022

@sixwaaaay Do you want this?

root# export X="aaa
> bbb"

root# echo "$X"
aaa
bbb

root# _output/nerdctl run --rm --env X alpine printenv X
aaa
bbb

liubin added a commit to liubin/nerdctl that referenced this issue Nov 19, 2022
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
liubin added a commit to liubin/nerdctl that referenced this issue Nov 19, 2022
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
liubin added a commit to liubin/nerdctl that referenced this issue Nov 21, 2022
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
liubin added a commit to liubin/nerdctl that referenced this issue Nov 21, 2022
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
stillfox-lee pushed a commit to stillfox-lee/nerdctl that referenced this issue Dec 27, 2022
Add a function to process env/envfile specified by users
and set value for env with no value has been set.

Fixes: containerd#1487

Signed-off-by: bin liu <liubin0329@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants