Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

windows: bash-style eval shown in cmd.exe/powershell #733

Closed
ahmetb opened this issue Mar 6, 2015 · 24 comments
Closed

windows: bash-style eval shown in cmd.exe/powershell #733

ahmetb opened this issue Mar 6, 2015 · 24 comments

Comments

@ahmetb
Copy link
Contributor

ahmetb commented Mar 6, 2015

←[34mINFO←[0m[0000] Creating SSH key...
←[34mINFO←[0m[0002] Creating VirtualBox VM...
←[34mINFO←[0m[0025] Starting VirtualBox VM...
←[34mINFO←[0m[0030] Waiting for VM to start...
←[34mINFO←[0m[0066] "docker-vb" has been created and is now the active machine.
←[34mINFO←[0m[0066] To point your Docker client at it, run this in your shell: $(docker-machine env docker-vb)

the last line doesn't make much sense as cmd.exe/powershell won't support it. We must find the windows equivalent (can't tell from off the top of my head) or tell people what to do instead.

@ehazlett
Copy link
Contributor

ehazlett commented Mar 6, 2015

Thanks! I think, for now at least, we recommend that users install msysgit which gives them bash I believe and this works. I agree with you we need to get to supporting cmd.exe/powershell at some point.

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 6, 2015

@ehazlett I am hoping to help with that in the long term. I wasn't aware of msysgit recommendation since I haven't seen it in the docs https://docs.docker.com/machine/

@ehazlett
Copy link
Contributor

ehazlett commented Mar 6, 2015

@ahmetalpbalkan ugh well then it was removed from the readme. It was in there at one point. I'll get it back. Thanks!

@ehazlett
Copy link
Contributor

ehazlett commented Mar 6, 2015

and thanks for helping! it is greatly appreciated!

@sthulb
Copy link
Contributor

sthulb commented Mar 6, 2015

The console on windows bothers me. Perhaps we can have console adapters, especially one for windows.

@StefanScherer
Copy link
Member

Perhaps depending on the parent process docker-machine.exe could show a different hint for the user.

For a cmd.exe this does the trick:

To point your Docker client at it, run this in your shell:  for /f "tokens=2" %i in ('docker-machine env docker-vb') do set %i

There should be a similar solution running from a powershell, but I haven't tried it yet.

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 21, 2015

There are still bunch of weird ssh-keygen/openssl bugs with mingw/cygwin installations and almost nobody can get it working right at this point. Telling people to just use set x=y (on cmd.exe) or $env:x=y (on ps) is probably fair enough at this point.

@ehazlett
Copy link
Contributor

@ahmetalpbalkan perhaps we could brainstorm the best way to support windows clients? I would like to get a "recommended" path for windows users (shell, env, etc).

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 23, 2015

@ehazlett definitely, if this works out of the box on cmd.exe or msys very easily, that'd be nice.

@silarsis
Copy link

I'd be keen to help with powershell support - right now I have a powershell function that parses the export lines and sets variables accordingly, but it's not a good solution - I'd much rather docker-machine recognised it was in powershell and actually set the variables for me.

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 28, 2015

@silarsis I recently tackled this problem in boot2docker shellinit: boot2docker/boot2docker-cli#356

Unfortunately there is no way to find out if we are running on cmd or powershell. (Unless we do win32 api calls and try to find name of parent process, which is very hacky).

However we were able to support this for powershell:

boot2docker shellinit | Invoke-Expression

Because I couldnt find an easy way to eval things in cmd.exe and I decided making powershell output the only stdout is good enough.

@silarsis
Copy link

I don't even mind if there's no automatic recognition - docker-machine env --powershell would be fine.

I'm new to powershell - is it possible to set env variables in a sub-process, or is that restricted the same way bash is? I ask because I'm wondering if the docker-machine env | Invoke-Expression pattern is appropriate, or if docker-machine can just set the variables and be done with it...?

@znmeb
Copy link

znmeb commented Mar 30, 2015

I don't know PowerShell at all. At this point, I'd settle for something that works exactly like Boot2Docker for Windows with Client Hyper-V replacing VirtualBox. If that's not possible, I'll probably end up rolling my own.

On a Windows system, you have three mutually exclusive options:

  1. Buy a VMWare Workstation license,
  2. Use the open source licensed subset of VirtualBox, or
  3. For Windows 8 or later, turn on Client Hyper-V.

You can only pick one, and right now, the second option is the only one that works.

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 30, 2015

@silarsis setting environment variables in sub-processes doesn't due to the way operating systems work, probably not specific to bash or powershell. :) Piping it to Invoke-Expression seems like a good way to go.

@znmeb (1) probably won't work (2) is what we have today (3) only ships in Windows Professional SKUs and is not enabled by default. And (2)-(3) cannot coexist on the same machine (i.e. you can't use VBox while Hyper-V is enabled). Today we have machine drivers for Hyper-V and VirtualBox and I believe both works just fine on windows and I'm not sure how all these are relevant to the shellinit discussion here? 😄

@ahmetb
Copy link
Contributor Author

ahmetb commented Mar 30, 2015

@silarsis also, I liked the idea of something like shellinit --shellname. Not only we can do best effort when the argument is omitted (esp. on posix), we can print cleaner output for ps and cmd cases.

@tknerr
Copy link

tknerr commented Apr 13, 2015

+1 for shellinit --<shellname>. Seeing this in other places too and seems pretty intuitive. If <shellname> is omitted one could still default to auto-detecing / guessing

@ehazlett
Copy link
Contributor

+1 for env --shellname as well and auto-detecting if missing.

@ahmetb
Copy link
Contributor Author

ahmetb commented Apr 29, 2015

@ehazlett just remembered you were asking me about this on IRC. did you write code for it or should I submit a PR?

@ehazlett
Copy link
Contributor

@ahmetalpbalkan PR - #1033 -- would love your feedback :)

@ewindisch
Copy link

nevermind - will confirm with newer build.

@ahmetb
Copy link
Contributor Author

ahmetb commented Jun 18, 2015

#ehazlett I see PR #1033 is merged, but it only addresses powershell. I still see the 'bash'-oriented suggestion with standard Windows cmd.exe.

@ewindisch is SHELL or TERM set in your windows console? If so that's gonna print bash output.

@nathanleclaire
Copy link
Contributor

I think this should be pretty well-rounded now, but please open a new issue if there are unexpected workflow consequences.

@jmauerhan
Copy link

for /f "tokens=2" %i in ('docker-machine env docker-vb') do set %i

The command above (suggested by #733 (comment)) works for me, but I also get these two errors:

> set Run                                                         
Environment variable Run not defined                              

> set FOR                                                         
Environment variable FOR not defined                              

@StefanScherer
Copy link
Member

@jmauerhan The docker-machine 0.6.0 binary shows a little different command if you just run docker-machine env docker-vb from a CMD.exe shell.

FOR /f "tokens=*" %i IN ('"docker-machine.exe" env dev') DO %i

This "executes" the REM comment lines without an error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants