fsouza / go-dockerclient Goto Github PK
View Code? Open in Web Editor NEWGo 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 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
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)
}
}
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?
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
}
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
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!
the docker API supports builds a image from a dockerfile configuration,and i think go-dockerclient needs to implement it too,I'm working on this feature now.
ping @fsouza
Perhaps AttachToContainerOptions.InputFile should be a io.Reader and be named InputStream instead.
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)?
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.
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.
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
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?
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
As described in tsuru/docker-cluster#9.
I'm a bit lost with https://github.com/fsouza/go-dockerclient/blob/master/testing/server.go
I though I would be able to use it as a fake local server, but most of the funcs are private. Therefore, if I "wait" for a container in my tests, I don't have anything to change the running state to false
, and exit of the for loop here:
https://github.com/fsouza/go-dockerclient/blob/master/testing/server.go#L358
Maybe I'm missing something?
Thanks
... or whatever for GET /containers/(id)/changes API
As of version 1.0.0 docker returns ints as floats which breaks the json unmarshalling process with:
json: cannot unmarshal number 6.7108864e+07 into Go value of type int64
I think this line is the culprit: https://github.com/fsouza/go-dockerclient/blob/master/client.go#L317
Maybe something like this would fix it?
if u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "unix" && u.Scheme != "tcp" {
RemoveContainer should have an argument, specifying if it should remove volumes (v=0/v=1)
Add a test for pull request #53.
I wasn't able to find the documentation for the endpoint, but it exists :)
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).
I've found that committing containers with the client produces an image without a CMD. I've created an isolated example here to recreate:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.