You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 1, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 1, 2021. It is now read-only.
These commands produce no errors when executed directly (by pasting into the command line). I am not sure why command substitution fails.
boot2docker v1.4.1 (Git commit: 43241cb) is installed on OSX 10.10 with GNU Bash 4.3.30(1)-release (x86_64-apple-darwin14.0.0).
This issue seems to be different from #715, as none of my boot2docker-related paths contain whitespace (and there are no paths at all in the shellinit-generated output).
UPD: I just discovered that boot2docker shellinit sometimes produces commands in a different order:
This seems like some oddity with using both unset and export commands inside a command substitution. I've posted a question on StackExchange about this.
UPD: This is the expected behaviour, as explained in the accepted answer. This can be fixed by replacing $(boot2docker shellinit) with either of these:
eval"$(boot2docker shellinit)".<(boot2docker shellinit)# process substitution, requires Bash 4
Using the result of command substitution directly, i.e. $(boot2docker shellinit), will work correctly only when shellinit generates a single command or when all commands are export ones. In all other cases it will not work as intended, even if no error is produced.
which exports DOCKER_HOST variable with the new value, and DOCKER_TLS_VERIFY, DOCKER_CERT_PATH and unset variables without changing their values. This is obviously not the desired effect of the original commands.
@SvenDowideit, unfortunately this cannot be solved by just re-ordering the commands, or any other change in the output of boot2docker shellinit. That's because everything produced by an unquoted command substitution is being splitted and interpreted as one command. See my previous comment for details.
The solution is to quote command substitution, and then pass the resulting (non-splitted) string to eval:
eval"$(boot2docker shellinit)"
This will require no changes in the code, only changes in the documentation.
Hmm, using empty strings instead of unset commands is a clever idea =)
These can be distinguished by Bash, for example ${A:def} will not replace $A with def when A is empty (but ${A:-def} will). If Docker client treats null variables the same as unset ones, then it's probably ok.
Activity
skozin commentedon Jan 28, 2015
This seems like some oddity with using both
unsetandexportcommands inside a command substitution. I've posted a question on StackExchange about this.UPD: This is the expected behaviour, as explained in the accepted answer. This can be fixed by replacing
$(boot2docker shellinit)with either of these:Using the result of command substitution directly, i.e.
$(boot2docker shellinit), will work correctly only whenshellinitgenerates a single command or when all commands areexportones. In all other cases it will not work as intended, even if no error is produced.is equivalent to
which exports
DOCKER_HOSTvariable with the new value, andDOCKER_TLS_VERIFY,DOCKER_CERT_PATHandunsetvariables without changing their values. This is obviously not the desired effect of the original commands.is equivalent to
which fails because it tries to unset
DOCKER_HOST=tcp://192.168.59.103:2375, which is not a valid variable name.SvenDowideit commentedon Jan 29, 2015
oh wow, so its a really easy fix for us to order the commands right
thankyou for the details!
skozin commentedon Jan 29, 2015
@SvenDowideit, unfortunately this cannot be solved by just re-ordering the commands, or any other change in the output of
boot2docker shellinit. That's because everything produced by an unquoted command substitution is being splitted and interpreted as one command. See my previous comment for details.The solution is to quote command substitution, and then pass the resulting (non-splitted) string to
eval:This will require no changes in the code, only changes in the documentation.
SvenDowideit commentedon Jan 30, 2015
oh. I missread the
export ... unset ...version, oh boy.SvenDowideit commentedon Jan 30, 2015
ok, so
seems to allow the Docker client to correctly not use TLS
can we replace the unset's with export and get away with it?
skozin commentedon Jan 30, 2015
Hmm, using empty strings instead of
unsetcommands is a clever idea =)These can be distinguished by Bash, for example
${A:def}will not replace$AwithdefwhenAis empty (but${A:-def}will). If Docker client treats null variables the same as unset ones, then it's probably ok.I think this will be more correct, though:
because it doesn't perform unneeded export of the
exportvariable. Or, better yet:$(echo "export DOCKER_TLS_VERIFY='' DOCKER_HOST='tcp://10.10.10.2:2375' DOCKER_CERT_PATH=''")This is completely equivalent to the previous snippet, and is easier to understand.
UPD: According to the Go's os.Getenv() documentation, it doesn't distinguish between non-set and empty variables:
The related code in Docker, as expected, compares results of
os.Getenv(...)calls with an empty string, so this approach seems totally safe.SvenDowideit commentedon Jan 30, 2015
@tianon should we get this into 1.5.0 too?
skozin commentedon Jan 30, 2015
I think this is also applicable for docker machine's
envcommand.SvenDowideit commentedon Mar 3, 2015
ok, over it, I'm implementing this atm.
skozin commentedon Mar 24, 2015
Thanks for fixing this! =)