Coder Social home page Coder Social logo

fsouza / go-dockerclient Goto Github PK

View Code? Open in Web Editor NEW
2.1K 2.1K 561.0 4.75 MB

Go client for the Docker Engine API.

Home Page: https://pkg.go.dev/github.com/fsouza/go-dockerclient?tab=doc

License: BSD 2-Clause "Simplified" License

Go 99.92% Makefile 0.07% Dockerfile 0.01%
docker go golang hacktoberfest

go-dockerclient's Issues

ListContainers fails listing all containers

ListContainers with "docker.ListContainersOptions{All: true}" returns an empty list
while "docker.ListContainersOptions{All: false}" or "docker.ListContainersOptions{}"
returns the list of containers running

I'm using docker version 0.9.0.

my code:

package main
import (
    "fmt"
    "github.com/fsouza/go-dockerclient"
)
func main() {
    client, _ := docker.NewClient("unix:///var/run/docker.sock")
    conts, _ := client.ListContainers(docker.ListContainersOptions{All: true})
    for _, cont := range conts {
        fmt.Println("ID: ", cont.ID)
    }
}

BuildImage 404 error

Hi i am trying to create images using Dockerfile, here is the little script:

        endpoint := "unix:///var/run/docker.sock"
        client, err := docker.NewClient(endpoint)
        tt := time.Now()
        inputbuf, outputbuf := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
        tr := tar.NewWriter(inputbuf)
        tr.WriteHeader(&tar.Header{Name: "Dockerfile", Size: 10, ModTime: tt, AccessTime: tt, ChangeTime: tt})
        tr.Write([]byte("FROM ubuntu\n"))
        tr.Close()
        opts := docker.BuildImageOptions{
                Name:           "test",
                RmTmpContainer: true,
                SuppressOutput: false,
                NoCache:        true,
                InputStream:    inputbuf,
                OutputStream:   outputbuf,
        }
        if err := client.BuildImage(opts); err != nil {
                log.Fatalf("%v", err)
        }

The command reply with a 404 error code...

2014/06/24 15:05:06 HTTP code: 404

what i am missing?

InspectContainer dose not contain PortBindings info

My code is here:

type Container struct {
    ID string
        ......
    Volumes   map[string]string
    VolumesRW map[string]bool

    // Add by Li Bin
    HostConfig *HostConfig
}

// Add by Li Bin
func (p *HostConfig) unmarshal(raw json.RawMessage) bool {
    if err := json.Unmarshal(raw, p); err != nil {
        return false
    }
    return true
}

func (c *Client) InspectContainer(id string) (*Container, error) {
    path := "/containers/" + id + "/json"
    body, status, err := c.do("GET", path, nil)
    if status == http.StatusNotFound {
        return nil, &NoSuchContainer{ID: id}
    }
    if err != nil {
        return nil, err
    }
    var container Container
    err = json.Unmarshal(body, &container)
    if err != nil {
        return nil, err
    }

     // Add by Li Bin
    var doc struct {
        Things []json.RawMessage `json:"things"`
    }
    err = json.Unmarshal(body, &doc)
    if err != nil {
        return nil, err
    }
    for _, thing := range doc.Things {
        host := new(HostConfig)
        if host.unmarshal(thing) {
            container.HostConfig = host
        }
    }

    return &container, nil
}

Weird behaviour on ListImages function

I can't realize what is wrong with the example bellow:

https://github.com/wiliamsouza/go-dockerclient#example

It return:

ID: 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c
Virtual Size: 128029199
RepoTag: []
Repository:
Tag:
Created: 1365714795
Size: 128029199
ID: b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc
Virtual Size: 175307035
RepoTag: []
Repository:
Tag:
Created: 1364102658
Size: 77

and I expect it return info close to the output off docker images:

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 12.04 8dbd9e392a96 9 months ago 128 MB
ubuntu latest 8dbd9e392a96 9 months ago 128 MB
ubuntu precise 8dbd9e392a96 9 months ago 128 MB
ubuntu 12.10 b750fe79269d 10 months ago 175.3 MB
ubuntu quantal b750fe79269d 10 months ago 175.3 MB

docker version is:

Client version: 0.7.6
Go version (client): go1.2
Git commit (client): bc3b2ec
Server version: 0.7.6
Git commit (server): bc3b2ec
Go version (server): go1.2
Last stable version: 0.7.6

error when using a socket connection

using a unix socket to hit the API, i continuously get errors like this:

Post /images/create?fromImage=base: unsupported protocol scheme ""

does the client currently fully support these connections? it looks as is the generated URL is incorrect.

thanks!

Newbie question: Permission denied when trying to connect to docker

Hi guys!

From start I apologize for posting it here but I can see no mailling list or google group associated with go-dockerclient.

So when running:

endpoint := "unix:///var/run/docker.sock"
client, err := docker.NewClient(endpoint)

I am receiving

dial unix /var/run/docker.sock: permission denied

Is there a way to fix it from within the dockerclient, or should I modify my local docker installation (and how)?

Add support for multiple API versions

Docker API version 1.12 modifies the JSON format of multiple entities (Image and Container to name 2 crucial ones) but retains the prior format if you specify an older version in the path (e.g. /v1.11/images vs /images). The change landed with this commit: moby/moby@68fb7f4.

When you retrieve an Image, for example, versions less than 1.12 return the container config as container_config but the change in 1.12 is to use CamelCase for everything, so it's now ContainerConfig.

It would be nice to be able to specify the version to use when using this library, and to provide support for the different formats returned by the different versions.

broken drone.io and travis.ci builds in master

As the title says. The builds seems to be broken according to embedded README images. I would like to use the go client for docker, but it doesn't feel good if it seems like to be broken.

event listener sometimes doesn't work

Working on logspout, I found that every other time it runs, it doesn't consume events. I couldn't figure out any other variable. Literally, every other time I'd run the program that just listens for events, it would show events, the other time it would not.

Here is the test program I made to try and reproduce:
https://github.com/progrium/logspout/blob/master/utils/docker-listener.go

Running this will work half the time. Half the time it doesn't. But it doesn't seem like a race just because of how consistently it's every other time.

However, I discovered that by adding and removing an event listener first (uncomment those two lines), it works quite consistently. I cannot figure this out.

# docker version
Client version: 0.11.1
Client API version: 1.11
Go version (client): go1.2.1
Git commit (client): fb99f99
Server version: 0.11.1
Server API version: 1.11
Git commit (server): fb99f99
Go version (server): go1.2.1
Last stable version: 0.11.1

docker.APIInfo error

I'm getting errors building the current master against Docker's master.

/opt/go/src/github.com/fsouza/go-dockerclient/misc.go:37: undefined: docker.APIInfo
/opt/go/src/github.com/fsouza/go-dockerclient/misc.go:42: undefined: docker.APIInfo

I'm wondering if Docker has dropped the APIInfo type. Has anyone else seen this?

Pipe data to CreateContainer unsupported?

Is it possible to pipe data when creating a container? Using Docker's cli it's possible to via: cat somefile | sudo docker run -i -a stdin mybuilder dobuild

Can I somehow archive this using the go-dockerclient lib?

Thanks

client: Implement Events()

Events(since uint64) should return a channel (or take a channel and send data to it?) that will get /events updates. It must also gracefully handle network interruptions (reconnect with last good time value).

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.