Coder Social home page Coder Social logo

Comments (4)

DimShadoWWW avatar DimShadoWWW commented on April 28, 2024

it fails in line 63 of container.go

err = json.Unmarshal(body, &containers)

I had to connect directly to docker, reusing the code of the client API and http

from go-dockerclient.

fsouza avatar fsouza commented on April 28, 2024

@DimShadoWWW looks like Docker has changed the API, I will have a look.

It seems that you managed to get it working, what did you do? Would you be willing to send a patch?

Thanks!

from go-dockerclient.

DimShadoWWW avatar DimShadoWWW commented on April 28, 2024

@fsouza .. this is the code of my function (I hasn't clean or organized yet):

func (l *Lib) GetContainers(all bool) ([]APIContainers, error) {
    query := "0"
    if all {
        query = "1"
    }
    req, err := http.NewRequest("GET", "/containers/json?all="+query, nil)
    if err != nil {
        fmt.Errorf("ERROR: ", err)
        return nil, err
    }
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("User-Agent", "mine")
    var resp *http.Response
    dial, err := net.Dial("unix", "/var/run/docker.sock")
    if err != nil {
        fmt.Errorf("ERROR: ", err)
        return nil, err
    }
    clientconn := httputil.NewClientConn(dial, nil)
    resp, err = clientconn.Do(req)
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Errorf("ERROR: ", err)
        return nil, err
    }
    outs := engine.NewTable("Created", 0)
    if _, err := outs.ReadListFrom(body); err != nil {
        fmt.Errorf("ERROR: ", err)
        return nil, err
    }
    var containers []APIContainers
    for _, out := range outs.Data {
        var c APIContainers
        c.ID = out.Get("Id")
        c.Names = out.GetList("Names")
        c.Image = out.Get("Image")
        c.Command = out.Get("Command")
        c.Created = out.GetInt64("Created")
        c.Status = out.Get("Status")
        c.SizeRw = out.GetInt64("SizeRw")
        c.SizeRootFs = out.GetInt64("SizeRootFs")
        ports := engine.NewTable("", 0)
        ports.ReadListFrom([]byte(out.Get("Ports")))
        ports.SetKey("PublicPort")
        ports.Sort()
        for _, port := range ports.Data {
            var p APIPort
            p.IP = port.Get("IP")
            p.PrivatePort = port.GetInt64("PrivatePort")
            p.PublicPort = port.GetInt64("PublicPort")
            p.Type = port.Get("Type")
            c.Ports = append(c.Ports, p)
        }
        containers = append(containers, c)
    }
    return containers, nil
}

from go-dockerclient.

fsouza avatar fsouza commented on April 28, 2024

It's working with the latest version of Docker.

I've tried Docker 1.0 and 1.1. I'm closing this issue.

@DimShadoWWW please let me know if you find this or any other issue in the future! :)

from go-dockerclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.