summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@gmail.com>2018-05-13 14:54:17 -0400
committerAlex Goodman <wagoodman@gmail.com>2018-05-13 14:54:49 -0400
commit8f16cb8a712f0fdd0f07ea05a733e65bc6a45116 (patch)
tree900d2fc4c4712c2b5932a32b3ac27af2e3621f1c /main.go
parentf12ac1d63bcc8be1c97585ccbad55ba3c4d9c201 (diff)
just getting comfy with docker api and images
Diffstat (limited to 'main.go')
-rw-r--r--main.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..7bae80c
--- /dev/null
+++ b/main.go
@@ -0,0 +1,56 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/docker/docker/client"
+ "golang.org/x/net/context"
+)
+
+func main() {
+ ctx := context.Background()
+ cli, err := client.NewEnvClient()
+ if err != nil {
+ panic(err)
+ }
+
+ // imageID := "golang:alpine"
+ imageID := "die-test:latest"
+
+ for {
+ inspect, _, err := cli.ImageInspectWithRaw(ctx, imageID)
+ if err != nil {
+ panic(err)
+ }
+
+ history, err := cli.ImageHistory(ctx, imageID)
+ if err != nil {
+ panic(err)
+ }
+
+ historyStr, err := json.MarshalIndent(history, "", " ")
+ if err != nil {
+ panic(err)
+ }
+
+ layerStr := ""
+ for idx, layer := range inspect.RootFS.Layers {
+ prefix := "├── "
+ if idx == len(inspect.RootFS.Layers)-1 {
+ prefix = "└── "
+ }
+ layerStr += fmt.Sprintf("%s%s\n", prefix, layer)
+ }
+
+ fmt.Printf("Image: %s\nId: %s\nParent: %s\nLayers: %d\n%sHistory: %s\n", imageID, inspect.ID, inspect.Parent, len(inspect.RootFS.Layers), layerStr, historyStr)
+
+ fmt.Println("\n")
+
+ if inspect.Parent == "" {
+ break
+ } else {
+ imageID = inspect.Parent
+ }
+ }
+}