Skip to content

Commit

Permalink
Better error detection for nonexistent/nonrunning containers in ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayliss committed Feb 10, 2016
1 parent 6c5da56 commit a39fda5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/wrappers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"fmt"
"github.com/codegangsta/cli"
"os"
Expand Down Expand Up @@ -42,14 +43,16 @@ var CmdSsh = cli.Command{
Name: "ssh",
Usage: "Shell into a running docker container",
Action: func(ctx *cli.Context) {
args := []string{"docker", "exec", "-it"}
for _, i := range ctx.Args() {
args = append(args, fmt.Sprintf("$(docker-compose ps -q %s)", i))
name := ctx.Args()[0]
contid, err := exec.Command("docker-compose", "ps", "-q", name).Output()
contid = bytes.TrimSpace(contid)
if err != nil || bytes.Equal(contid, []byte("")) {
fmt.Printf("Could not find container %s. Are you sure it's running?\n", name)
os.Exit(1)
}
args = append(args, "/bin/bash")

fmt.Printf("running: %s\n", sliceToString(args))
cmd := exec.Command("bash", "-c", sliceToString(args))
fmt.Printf("running: docker exec -it $(docker-compose ps -q %s) /bin/bash \n", name)
cmd := exec.Command("docker", "exec", "-it", string(contid), "/bin/bash")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
Expand Down
1 change: 1 addition & 0 deletions vagabond.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func main() {
cmd.CmdDiagnose,
cmd.CmdSelfUpdate,

// Simple wrapper commands:
cmd.CmdUp,
cmd.CmdDestroy,
cmd.CmdHalt,
Expand Down

0 comments on commit a39fda5

Please sign in to comment.