-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
special characters including hyphen is not working as identifier in docker build arg key #4458
Comments
Build-args are set as environment-variables in your When interpolating them it depends on the shell what's accepted, and how these are handled. The daemon (and OCI runtime) generally accept anything, except docker build --progress=plain --build-arg 'key2-temp=hello world' -<<'EOF'
FROM alpine
ARG key2-temp
RUN env
EOF Which shows this output for the #5 [2/2] RUN env
#5 0.150 key2-temp=hello world
#5 0.150 SHLVL=1
#5 0.150 HOME=/root
#5 0.150 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#5 0.150 PWD=/
#5 DONE 0.2s Or, using docker run --name foo --env "hello-world=hello-value" --env "hello world=hello value" --env "hello.world=hello value" alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=1c5f844cc8c1
hello world=hello value
hello.world=hello value
hello-world=hello-value
HOME=/root Or inspecting the container: docker inspect --format '{{json .Config.Env}}' foo | jq .
[
"hello world=hello value",
"hello.world=hello value",
"hello-world=hello-value",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
] The POSIX specification allows for most characters (except
Unfortunately that also means that we cannot validate characters; we once did, but this caused issues as some tools depend on "invalid" env-vars (moby/moby#16585), so we had to revert (moby/moby#16608). As my earlier example shows; these vars can be set in the environment, however, it depends on the shell how they are interpreted. In your Hyphens also have special meaning in most (POSIX compliant) shells; https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_06_02 So for example
docker run --rm --env "hello-world=hello-value" alpine sh -c 'echo ${hello-world}'
world So in general, I would recommend sticking to |
Maybe the docs could be improved here? \cc @dvdksn |
Description
special characters like hyphen, space is not working in docker build arg key (only under score _ works in key)
Reproduce
--build-arg 'key2-temp'='test value2' --build-arg 'key1 test'='test 1' is not working
ARG key2-temp
RUN echo $key2-temp # it prints -temp2 instead of its value.
Expected behavior
it should print test value2
docker version
docker info
Additional Info
Is there any documentation which suggests that we cant use special characters including hyphen will not work in docker build arg key?
The text was updated successfully, but these errors were encountered: