Development language GolangQuerying the Mirror list using UNIX domain sockets and Docker daemon interaction
Package Main
Import (
"fmt""net""io/ioutil""encoding/json"
)
Type Image struct {
Created uint64Id stringParentId stringRepoTags []stringSize uint64VirtualSize uint64
}
Func Main () {
addr := net.UnixAddr{"/var/run/docker.sock", "unix"}conn, err := net.DialUnix("unix", nil, &addr)if err != nil { panic(err)}_, err = conn.Write([]byte("GET /images/json HTTP/1.0\r\n\r\n"))if err != nil { panic(err)}result, err_conn := ioutil.ReadAll(conn)if err_conn != nil { panic(err_conn)}body := getBody(result[:])var images []Imageerr_js := json.Unmarshal(body, &images)if err_js != nil { panic(err_js)}fmt.Println("len of images: ", len(images))fmt.Println("image.Id: ", images[0].Id)
}
Func getbody (Result []byte) (Body []byte) {
for i := 0; i <= len(result) - 4; i++ { if result[i] == 13 && result[i+1] == 10 && result[i+2] == 13 && result[i+3] == 10 { body = result[i+4:] break }}return
}
Interacting with Golang and Docker daemons