55 "fmt"
66 "os"
77 "runtime"
8- "strings"
98 "time"
109
1110 _ "github.com/boot2docker/boot2docker-cli/dummy"
@@ -61,44 +60,50 @@ func cmdUp() error {
6160 }
6261 print ("\n " )
6362
64- fmt .Printf ("Started." )
63+ fmt .Printf ("Started.\n " )
6564
6665 if IP == "" {
6766 // lets try one more time
6867 time .Sleep (600 * time .Millisecond )
69- fmt .Printf (" Trying to get IP one more time" )
68+ fmt .Printf (" Trying to get IP one more time\n " )
7069
7170 IP = RequestIPFromSSH (m )
7271 }
72+ // Copying the certs here - someone might have have written a Windows API client.
73+ certPath := RequestCertsUsingSSH (m )
7374 switch runtime .GOOS {
7475 case "windows" :
75- fmt .Printf ("Docker client does not run on Windows for now. Please use" )
76- fmt .Printf (" \" %s\" ssh" , os .Args [0 ])
77- fmt .Printf ("to SSH into the VM instead." )
76+ fmt .Printf ("Docker client does not run on Windows for now. Please use\n " )
77+ fmt .Printf (" \" %s\" ssh\n " , os .Args [0 ])
78+ fmt .Printf ("to SSH into the VM instead.\n " )
7879 default :
7980 if IP == "" {
80- fmt .Fprintf (os .Stderr , "Auto detection of the VM's IP address failed." )
81- fmt .Fprintf (os .Stderr , "Please run `boot2docker -v up` to diagnose." )
81+ fmt .Fprintf (os .Stderr , "Auto detection of the VM's IP address failed.\n " )
82+ fmt .Fprintf (os .Stderr , "Please run `boot2docker -v up` to diagnose.\n " )
8283 } else {
8384 // Check if $DOCKER_HOST ENV var is properly configured.
84- if os .Getenv ("DOCKER_HOST" ) != fmt .Sprintf ("tcp://%s:%d" , IP , driver .DockerPort ) {
85- fmt .Printf ("To connect the Docker client to the Docker daemon, please set:" )
86- fmt .Printf (" export DOCKER_HOST=tcp://%s:%d" , IP , driver .DockerPort )
85+ socket := RequestSocketFromSSH (m )
86+ if os .Getenv ("DOCKER_HOST" ) != socket || os .Getenv ("DOCKER_CERT_PATH" ) != certPath {
87+ fmt .Printf ("\n To connect the Docker client to the Docker daemon, please set:\n " )
88+ fmt .Printf (" export DOCKER_HOST=%s\n " , socket )
89+ // Assume Docker 1.2.0 with TLS on...
90+ fmt .Printf (" export DOCKER_CERT_PATH=%s\n " , certPath )
8791 } else {
88- fmt .Printf ("Your DOCKER_HOST env variable is already set correctly." )
92+ fmt .Printf ("Your DOCKER_HOST env variable is already set correctly.\n " )
8993 }
9094 }
9195 }
96+ fmt .Printf ("\n " )
9297 return nil
9398}
9499
95100// Tell the user the config (and later let them set it?)
96101func cmdConfig () error {
97- dir , err := getCfgDir (".boot2docker" )
102+ dir , err := cfgDir (".boot2docker" )
98103 if err != nil {
99104 return fmt .Errorf ("Error working out Profile file location: %s" , err )
100105 }
101- filename := getCfgFilename (dir )
106+ filename := cfgFilename (dir )
102107 fmt .Printf ("boot2docker profile filename: %s" , filename )
103108 fmt .Println (printConfig ())
104109 return nil
@@ -217,6 +222,26 @@ func cmdStatus() error {
217222 return nil
218223}
219224
225+ // tell the User the Docker socket to connect to
226+ func cmdSocket () error {
227+ m , err := driver .GetMachine (& B2D )
228+ if err != nil {
229+ return fmt .Errorf ("Failed to get machine %q: %s" , B2D .VM , err )
230+ }
231+
232+ if m .GetState () != driver .Running {
233+ return fmt .Errorf ("VM %q is not running." , B2D .VM )
234+ }
235+
236+ Socket := RequestSocketFromSSH (m )
237+
238+ fmt .Fprintf (os .Stderr , "\n \t export DOCKER_HOST=" )
239+ fmt .Printf ("%s" , Socket )
240+ fmt .Fprintf (os .Stderr , "\n \n " )
241+
242+ return nil
243+ }
244+
220245// Call the external SSH command to login into boot2docker VM.
221246func cmdSSH () error {
222247 m , err := driver .GetMachine (& B2D )
@@ -236,17 +261,7 @@ func cmdSSH() error {
236261 i ++
237262 }
238263
239- sshArgs := append ([]string {
240- "-o" , "IdentitiesOnly=yes" ,
241- "-o" , "StrictHostKeyChecking=no" ,
242- "-o" , "UserKnownHostsFile=/dev/null" ,
243- "-o" , "LogLevel=quiet" , // suppress "Warning: Permanently added '[localhost]:2022' (ECDSA) to the list of known hosts."
244- "-p" , fmt .Sprintf ("%d" , m .GetSSHPort ()),
245- "-i" , B2D .SSHKey ,
246- "docker@localhost" ,
247- }, os .Args [i :]... )
248-
249- if err := cmdInteractive (B2D .SSH , sshArgs ... ); err != nil {
264+ if err := cmdInteractive (m , os .Args [i :]... ); err != nil {
250265 return fmt .Errorf ("%s" , err )
251266 }
252267 return nil
@@ -287,38 +302,6 @@ func cmdIP() error {
287302 return nil
288303}
289304
290- func RequestIPFromSSH (m driver.Machine ) string {
291- // fall back to using the NAT port forwarded ssh
292- out , err := cmd (B2D .SSH ,
293- "-v" , // please leave in - this seems to improve the chance of success
294- "-o" , "IdentitiesOnly=yes" ,
295- "-o" , "StrictHostKeyChecking=no" ,
296- "-o" , "UserKnownHostsFile=/dev/null" ,
297- "-p" , fmt .Sprintf ("%d" , m .GetSSHPort ()),
298- "-i" , B2D .SSHKey ,
299- "docker@localhost" ,
300- "ip addr show dev eth1" ,
301- )
302- IP := ""
303- if err != nil {
304- fmt .Fprintf (os .Stderr , "request ip from ssh error: %v" , err )
305- } else {
306- if B2D .Verbose {
307- fmt .Printf ("SSH returned: %s\n END SSH\n " , out )
308- }
309- // parse to find: inet 192.168.59.103/24 brd 192.168.59.255 scope global eth1
310- lines := strings .Split (out , "\n " )
311- for _ , line := range lines {
312- vals := strings .Split (strings .TrimSpace (line ), " " )
313- if len (vals ) >= 2 && vals [0 ] == "inet" {
314- IP = vals [1 ][:strings .Index (vals [1 ], "/" )]
315- break
316- }
317- }
318- }
319- return IP
320- }
321-
322305// Download the boot2docker ISO image.
323306func cmdDownload () error {
324307 fmt .Printf ("Downloading boot2docker ISO image..." )
0 commit comments