diff --git a/README.md b/README.md index b9a9dd2..d9fd954 100644 --- a/README.md +++ b/README.md @@ -189,12 +189,12 @@ Dockviz supports connecting to the Docker daemon directly. It defaults to `unix 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 -$ curl -s http://localhost:4243/containers/json?all=1 | dockviz containers --dot | dot -Tpng -o containers.png -$ echo -e "GET /images/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | dockviz images --tree -$ echo -e "GET /containers/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | dockviz containers --dot | dot -Tpng -o containers.png -$ echo -e "GET /images/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | docker run -i nate/dockviz images --tree -$ echo -e "GET /containers/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | docker run -i nate/dockviz containers --dot | dot -Tpng -o containers.png +$ curl -s http://localhost:4243/images/json?all=1 | dockviz --stdin images --tree +$ curl -s http://localhost:4243/containers/json?all=1 | dockviz --stdin containers --dot | dot -Tpng -o containers.png +$ echo -e "GET /images/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | dockviz --stdin images --tree +$ echo -e "GET /containers/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | dockviz --stdin containers --dot | dot -Tpng -o containers.png +$ echo -e "GET /images/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | docker run -i nate/dockviz --stdin images --tree +$ echo -e "GET /containers/json?all=1 HTTP/1.0\r\n" | nc -U /var/run/docker.sock | sed '1,/^[[:space:]]*$/d' | docker run -i nate/dockviz --stdin containers --dot | dot -Tpng -o containers.png ``` Note: GNU netcat doesn't support `-U` (UNIX socket) flag, so OpenBSD variant can be used. diff --git a/cli.go b/cli.go index b58ba95..4851e56 100644 --- a/cli.go +++ b/cli.go @@ -14,6 +14,7 @@ type GlobalOptions struct { TLSVerify bool `long:"tlsverify" description:"Use TLS and verify the remote"` Host string `long:"host" short:"H" value-name:"unix:///var/run/docker.sock" description:"Docker host to connect to"` Version func() `long:"version" short:"v" description:"Display version information."` + Stdin bool `long:"stdin" description:"Enable reading image information from stdin (pre-Docker-1.11 only)"` } var globalOptions GlobalOptions diff --git a/containers.go b/containers.go index 4a19997..de1f79a 100644 --- a/containers.go +++ b/containers.go @@ -37,7 +37,7 @@ func (x *ContainersCommand) Execute(args []string) error { return fmt.Errorf("error reading stdin stat", err) } - if (stat.Mode() & os.ModeCharDevice) == 0 { + if globalOptions.Stdin && (stat.Mode()&os.ModeCharDevice) == 0 { // read in stdin stdin, err := ioutil.ReadAll(os.Stdin) if err != nil { diff --git a/images.go b/images.go index fa2e988..ca202b7 100644 --- a/images.go +++ b/images.go @@ -51,7 +51,7 @@ func (x *ImagesCommand) Execute(args []string) error { return fmt.Errorf("error reading stdin stat", err) } - if (stat.Mode() & os.ModeCharDevice) == 0 { + if globalOptions.Stdin && (stat.Mode()&os.ModeCharDevice) == 0 { // read in stdin stdin, err := ioutil.ReadAll(os.Stdin) if err != nil {