just getting comfy with docker api and images
This commit is contained in:
parent
f12ac1d63b
commit
8f16cb8a71
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM alpine:latest
|
||||||
|
ADD README.md /somefile.txt
|
||||||
|
RUN cp /somefile.txt /root/somefile.txt
|
@ -1,2 +1,5 @@
|
|||||||
# docker-image-explorer
|
# docker-image-explorer
|
||||||
I'll probably rename this since it acronyms to D.I.E. ... details...
|
```
|
||||||
|
docker build -t . die-test:latest
|
||||||
|
go run main.go
|
||||||
|
```
|
56
main.go
Normal file
56
main.go
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user