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

Cannot run docker-machine in powershell #3152

Open
devshorts opened this issue Mar 5, 2016 · 6 comments
Open

Cannot run docker-machine in powershell #3152

devshorts opened this issue Mar 5, 2016 · 6 comments

Comments

@devshorts
Copy link

I did a fresh install of the docker toolbox on a new windows box today. I can run docker fine in the docker quickstart

akrop_000@AntonLaptop MINGW64 ~
$ docker-machine.exe ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DO
CKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.101:2376           v1
.10.2

But in powershell

> docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
default   -        virtualbox   Stopped                 Unknown

When trying to set env

> docker-machine env default --shell powershell
Error checking TLS connection: Host is not running

Seems like something may be wrong with ssh?

hine Version:  0.6.0, build e27fb87
Regenerating TLS certificates
Found binary path at C:\Program Files\Docker Toolbox\docker-machine.exe
Launching plugin server for driver virtualbox
Plugin server listening at address 127.0.0.1:3275
() Calling .GetVersion
Using API Version  1
() Calling .SetConfigRaw
() Calling .GetMachineName
command=configureAuth machine=default
Waiting for SSH to be available...
Getting to WaitForSSH function...
(default) Calling .GetSSHHostname
(default) Calling .GetSSHPort
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHUsername
Using SSH client type: external
{[-o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none docker@127.0.0.1 -o IdentitiesOnly=yes -i C:\Users\akrop_000\.docker\machine\machines\default\id_rsa -p 2844] C:\Program Files (x86)\Gow\bin\ssh.bat}
About to run SSH command:
exit 0
SSH cmd err, output: exit status 1: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Error getting ssh command 'exit 0' : Something went wrong running an SSH command!
command : exit 0
err     : exit status 1
output  : 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


Getting to WaitForSSH function...
(default) Calling .GetSSHHostname
(default) Calling .GetSSHPort
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHUsername
Using SSH client type: external
{[-o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none docker@127.0.0.1 -o IdentitiesOnly=yes -i C:\Users\akrop_000\.docker\machine\machines\default\id_rsa -p 2844] C:\Program Files (x86)\Gow\bin\ssh.bat}
About to run SSH command:
exit 0
SSH cmd err, output: exit status 1: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

I'm not sure. Any help would be appreciated

-- EDIT

I switched my ssh to be git ssh but still no dice

Calling .GetSSHUsername
Using SSH client type: external
{[-o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none docker@127.0.0.1 -o IdentitiesOnly=yes -i C:\Users\akrop_000\.docker\machine\machines\default\id_rsa -p 2844] C:\Program Files (x86)\Git\bin\ssh.exe}
About to run SSH command:
netstat -an
SSH cmd err, output: <nil>: Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp       32      0 10.0.2.15:22            10.0.2.2:6790           ESTABLISHED
tcp        0      0 10.0.2.15:22            10.0.2.2:6437           TIME_WAIT
tcp        0      0 :::2376                 :::*                    LISTEN
tcp        0      0 :::22                   :::*                    LISTEN
udp        0      0 0.0.0.0:45647           0.0.0.0:*
udp        0      0 0.0.0.0:35499           0.0.0.0:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node Path
unix  2      [ ACC ]     STREAM     LISTENING      20062 /var/lib/docker/network/files/60e9952cbbf4ed8d7bbeef75bc389238a339851e364c017bf532f5b7c1774446.sock
unix  2      [ ACC ]     SEQPACKET  LISTENING      14400 /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING      19943 /var/run/docker.sock
unix  2      [ ACC ]     STREAM     LISTENING      18430 /var/run/acpid.socket
unix  3      [ ]         DGRAM                     14409
unix  3      [ ]         STREAM     CONNECTED      23153
unix  3      [ ]         DGRAM                     14410
unix  3      [ ]         STREAM     CONNECTED      23152

(default) Calling .GetSSHHostname
(default) Calling .GetSSHPort
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHKeyPath
(default) Calling .GetSSHUsername
Using SSH client type: external
{[-o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none docker@127.0.0.1 -o IdentitiesOnly=yes -i C:\Users\akrop_000\.docker\machine\machines\default\id_rsa -p 2844] C:\Program Files (x86)\Git\bin\ssh.exe}
About to run SSH command:
sudo mkdir -p /var/lib/boot2docker
SSH cmd err, output: <nil>:
(default) Calling .GetMachineName
(default) Calling .GetIP
(default) DBG | COMMAND: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe showvminfo default --machinereadable
(default) DBG | STDOUT:
(default) DBG | {
(default) DBG | name="default"
Host is not running
C:\Projects> docker-machine.exe ls
NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
default   -        virtualbox   Stopped                 Unknown

-- EDIT

turns it this is somehow related to running powershell in admin mode. After changing the ssh env var path I can run docker-machine fine in not powershell admin mode.

@pcgeek86
Copy link

pcgeek86 commented Mar 7, 2016

@devshorts It appears that docker-machine has a bug with spaces in file paths. It's trying to invoke the SSH executable, but it's failing to resolve the full file path under c:\Program Files, instead truncating it to c:\Program. This is actually a common problem with software that isn't tested with spaces in filesystem paths. I'd suggest updating the title of your issue report to help gain visibility to this.

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell

@alixandru
Copy link

This is caused by Gow. Gow has a ssh command which is an alias to plink. It looks like when ran from Windows CMD, docker-machine uses whatever is in the path for ssh and cannot work with plink as a ssh replacement.

I get the same error as the OP when I run docker-machine with Gow in my PATH. Here's my output from Windows CMD:

>docker-machine ls
NAME     ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
docker   *        virtualbox   Running                 Unknown   Something went wrong running an SSH command!
command : ip addr show dev eth1
err     : exit status 1
output  : 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

From Git Bash, I get no error whatsoever:

MINGW64 ~
$ docker-machine ls
NAME     ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
docker   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.10.3

If I take Gow out from my PATH (so no ssh command in my path), I get no error in Windows CMD.

The ssh command from Gow looks like this:

"C:\Program Files (x86)\Gow\bin\ssh.bat"

@echo off
plink %1 %2 %3 %4 %5 %6 %7 %8 %9

@DmitryEfimenko
Copy link

+1. I created docker-cmd-js, which should help running docker commands on Windows. Most common usage I can see would be using it in gulp. See blog about it if interested. Everything works fine until I execute gulp in a command line with Administrator mode.

@geronimus
Copy link

This appears to be a bug in golang's native exec.Command function, as per this issue.

The offending code is in the getSSHCmd function, currently at line 376 of:
machine/libmachine/ssh/client.go

Problem: I'm not currently familiar enough with the Go language to propose any kind of Pull Request, but I'm sure there's something simple that can be done to resolve this.

Of course, the work-around is to use some kind of mingw bash shell to run docker-machine, but because it already detects the OS as Windows, you have to remember to add the --shell bash argument to commands like docker env. Otherwise you get commands written for cmd.exe, rather than bash or Powershell.

@W1M0R
Copy link

W1M0R commented Jul 2, 2018

I can confirm that this problem still exists.

My setup:
Ubuntu 16.04 Server LTS
docker-machine version 0.15.0 build b48dc28d
PowerShell Core 6.1.0-preview.2

Calling docker-machine or ssh from PowerShell scripts, causes timeouts and "hidden" interactive ssh sessions, etc. However, interactive ssh sessions do work when calling ssh directly from a PowerShell prompt (pwsh).

Perhaps the problem is related to these issues:

  1. Remote SSH commands require double escaping before hitting the DefaultShell PowerShell/Win32-OpenSSH#1082
  2. https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core?view=powershell-6#setup-on-linux-ubuntu-1404-machine

The way that I resolve most of my SSH-related issues, is by letting PowerShell start a bash process that in turn executes the relevant docker-machine command.

@oke-aditya
Copy link

Note I am using Windows 10 Pro with Hyper-V and docker for windows.
Not docker toolbox and virtualbox.

Now docker-machine runs in the powershell and git bash.
The problem might be because.

  • I had no docker-machine.exe file created after the above process.

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

7 participants