From 7b58366a10fdb0c57f94f96cf519cc4118684d16 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 17 Aug 2015 19:44:02 -0700 Subject: [PATCH 1/2] add stub for help --- containers.go | 2 +- help.go | 22 ++++++++++++++++++++++ images.go | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 help.go diff --git a/containers.go b/containers.go index 2029a42..2db8415 100644 --- a/containers.go +++ b/containers.go @@ -57,7 +57,7 @@ func (x *ContainersCommand) Execute(args []string) error { clientContainers, err := client.ListContainers(docker.ListContainersOptions{All: true}) if err != nil { - return err + return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) } var conts []Container diff --git a/help.go b/help.go new file mode 100644 index 0000000..a03ad06 --- /dev/null +++ b/help.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +type HelpCommand struct { + // nothing yet +} + +var helpCommand HelpCommand + +func (x *HelpCommand) Execute(args []string) error { + fmt.Println("stub help is here") + + return nil +} + +func init() { + parser.AddCommand("help", + "Help for this tool.", + "", + &helpCommand) +} diff --git a/images.go b/images.go index bfe3289..605f323 100644 --- a/images.go +++ b/images.go @@ -59,7 +59,7 @@ func (x *ImagesCommand) Execute(args []string) error { clientImages, err := client.ListImages(docker.ListImagesOptions{All: true}) if err != nil { - return err + return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) } var ims []Image From b911e691800f7dbe762c4d8ee4d438ee21c336f8 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Tue, 18 Aug 2015 06:33:22 -0700 Subject: [PATCH 2/2] fill in help, add hint when running in docker --- Dockerfile | 1 + containers.go | 6 +++++- help.go | 24 ++++++++++++++++++++++-- images.go | 6 +++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1ef506..b35fb5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM scratch COPY dockviz / +ENV IN_DOCKER true ENTRYPOINT ["/dockviz"] diff --git a/containers.go b/containers.go index 2db8415..c42f471 100644 --- a/containers.go +++ b/containers.go @@ -57,7 +57,11 @@ func (x *ContainersCommand) Execute(args []string) error { clientContainers, err := client.ListContainers(docker.ListContainersOptions{All: true}) if err != nil { - return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) + if in_docker := os.Getenv("IN_DOCKER"); len(in_docker) > 0 { + return fmt.Errorf("Unable to access Docker socket, please run like this:\n docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz containers \nFor more help, run 'dockviz help'") + } else { + return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) + } } var conts []Container diff --git a/help.go b/help.go index a03ad06..6dae6f9 100644 --- a/help.go +++ b/help.go @@ -9,14 +9,34 @@ type HelpCommand struct { var helpCommand HelpCommand func (x *HelpCommand) Execute(args []string) error { - fmt.Println("stub help is here") + fmt.Println(`Dockviz: Visualizing Docker Data + +Connecting to Docker: + +Dockviz supports connecting to the Docker daemon directly. It defaults to +'unix:///var/run/docker.sock', but respects the following as well: + +* The 'DOCKER_HOST', 'DOCKER_CERT_PATH', and 'DOCKER_TLS_VERIFY' environment + variables, as set up by boot2docker or docker-machine. +* Command line arguments (e.g. '--tlscacert'), like those that Docker itself + supports. + +Dockviz also supports receiving Docker image or container json data on standard +input: curl -s http://localhost:4243/images/json?all=1 | dockviz images --tree + +Visualizing: + +Dockviz can visualize both images and containers. For more information on the +options each subcommand supports, run them with the '--help' flag (e.g. +'dockviz images --help'). +`) return nil } func init() { parser.AddCommand("help", - "Help for this tool.", + "Help for dockviz.", "", &helpCommand) } diff --git a/images.go b/images.go index 605f323..018a85b 100644 --- a/images.go +++ b/images.go @@ -59,7 +59,11 @@ func (x *ImagesCommand) Execute(args []string) error { clientImages, err := client.ListImages(docker.ListImagesOptions{All: true}) if err != nil { - return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) + if in_docker := os.Getenv("IN_DOCKER"); len(in_docker) > 0 { + return fmt.Errorf("Unable to access Docker socket, please run like this:\n docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz images \nFor more help, run 'dockviz help'") + } else { + return fmt.Errorf("Unable to connect: %s\nFor help, run 'dockviz help'", err) + } } var ims []Image