Interacting with Golang and Docker daemons

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.