Giter Club home page Giter Club logo

dockerclient's Introduction

Docker client library in Go

GoDoc

No longer well-maintained docker client library. Docker's supported engine API client for go is docker/engine-api.

How to use it?

Here is an example showing how to use it:

package main

import (
	"github.com/samalba/dockerclient"
	"log"
	"time"
	"os"
)

// Callback used to listen to Docker's events
func eventCallback(event *dockerclient.Event, ec chan error, args ...interface{}) {
	log.Printf("Received event: %#v\n", *event)
}

func main() {
	// Init the client
	docker, _ := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)

	// Get only running containers
	containers, err := docker.ListContainers(false, false, "")
	if err != nil {
		log.Fatal(err)
	}
	for _, c := range containers {
		log.Println(c.Id, c.Names)
	}

	// Inspect the first container returned
	if len(containers) > 0 {
		id := containers[0].Id
		info, _ := docker.InspectContainer(id)
		log.Println(info)
	}

	// Build a docker image
	// some.tar contains the build context (Dockerfile any any files it needs to add/copy)
	dockerBuildContext, err := os.Open("some.tar")
	defer dockerBuildContext.Close()
	buildImageConfig := &dockerclient.BuildImage{
			Context:        dockerBuildContext,
			RepoName:       "your_image_name",
			SuppressOutput: false,
	}
	reader, err := docker.BuildImage(buildImageConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Create a container
	containerConfig := &dockerclient.ContainerConfig{
		Image: "ubuntu:14.04",
		Cmd:   []string{"bash"},
		AttachStdin: true,
		Tty:   true}
	containerId, err := docker.CreateContainer(containerConfig, "foobar", nil)
	if err != nil {
		log.Fatal(err)
	}

	// Start the container
	hostConfig := &dockerclient.HostConfig{}
	err = docker.StartContainer(containerId, hostConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Stop the container (with 5 seconds timeout)
	docker.StopContainer(containerId, 5)

	// Listen to events
	docker.StartMonitorEvents(eventCallback, nil)

	// Hold the execution to look at the events coming
	time.Sleep(3600 * time.Second)
}

Maintainers

List of people you can ping for feedback on Pull Requests or any questions.

dockerclient's People

Contributors

06wagon avatar abronan avatar aluzzardi avatar boaz0 avatar crosbymichael avatar daaku avatar dennisdenuto avatar devfacet avatar discordianfish avatar divideandconquer avatar djmaze avatar dnephin avatar dongluochen avatar donhcd avatar ehazlett avatar epipho avatar jimmyxian avatar keegancsmith avatar lebauce avatar mountkin avatar mssola avatar philips avatar pwnall avatar samalba avatar tianon avatar tonistiigi avatar uniseraph avatar vieux avatar wrotki avatar wyvernblack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockerclient's Issues

Inspecting a Network, doesn't give me the Container ID associated with the network

When I query the Network and associated Containers on Docker CLI, I get the following:

root@ubuntu:~# docker network inspect b1
[
    {
        "Name": "b1",
        "Id": "52a3537307b177688b2684a5448396e6bcdded9f9e4b9ee9175c7b84fcbb6fe0",
        "Scope": "local",
        "Driver": "nuage",
        "EnableIPv6": false,
        "IPAM": [....],
        "Internal": false,
        "Containers": {
            "9e70c53a64406f3e8e7385e2efb93c7dd14278c8d5163c2c0137f7a80c1ade1c": {
                "Name": "kickass_allen",
                "EndpointID": "8121ce08011b3dc689de821d7eaccb1ff37f0480928d78a9f49c36263d9d8831",
                "MacAddress": "7a:42:3b:2e:a4:bf",
                "IPv4Address": "10.107.54.2/24",
                "IPv6Address": ""
            }
        },
[...]
    }
]

I can get the list of containers associated with that Network. the key for those container is the ID of that container (in this case 9e70c...).

However, when I use this dockerclient lib, the key becomes the Endpoint with an added substring of ep-

map[ep-8121ce08011b3dc689de821d7eaccb1ff37f0480928d78a9f49c36263d9d8831:{kickass_allen 8121ce08011b3dc689de821d7eaccb1ff37f0480928d78a9f49c36263d9d8831 7a:42:3b:2e:a4:bf 10.107.54.2/24 }]

Since I need to report the Container ID, I need to make an extra call to list the containers and match the name to the ID.

Would it be possible to get the container ID as the key when inspecting networks ?

Thanks

the value of ulimit can be -1

To set the ulimit unlimited, the value of ulimit can be -1. So parsing fails with this values. I am in stuck. Please see this issue ehazlett/interlock#154.

Any ideas?

Docker prints this:

            "Ulimits": [
                {
                    "Name": "memlock",
                    "Hard": -1,
                    "Soft": -1
                }
            ],

At https://github.com/samalba/dockerclient/blob/master/types.go#L516-L520

type Ulimit struct {
    Name string `json:"name"`
    Soft uint64 `json:"soft"`
    Hard uint64 `json:"hard"`
}

And for information https://github.com/docker/go-units/blob/master/ulimit.go#L9-L21

// Ulimit is a human friendly version of Rlimit.
type Ulimit struct {
    Name string
    Hard int64
    Soft int64
}

// Rlimit specifies the resource limits, such as max open files.
type Rlimit struct {
    Type int    `json:"type,omitempty"`
    Hard uint64 `json:"hard,omitempty"`
    Soft uint64 `json:"soft,omitempty"`
}

And https://github.com/docker/go-units/blob/master/ulimit.go#L106-L114

// GetRlimit returns the RLimit corresponding to Ulimit.
func (u *Ulimit) GetRlimit() (*Rlimit, error) {
    t, exists := ulimitNameMapping[u.Name]
    if !exists {
        return nil, fmt.Errorf("invalid ulimit name %s", u.Name)
    }

    return &Rlimit{Type: t, Soft: uint64(u.Soft), Hard: uint64(u.Hard)}, nil
}

Full log:

$ docker version                                                                                                                                                                          Client:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Tue Apr 26 23:30:23 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Tue Apr 26 23:30:23 2016
 OS/Arch:      linux/amd64
$ docker-compose version                                                                                                                                                                  docker-compose version 1.7.0, build 0d7bf73
docker-py version: 1.8.0
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
$ uname -a                                                                                                                                                                                Linux dev 3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ cat docker-compose.yml                                                                                                                                                                  version: '2'
services:
  interlock:
    image: ehazlett/interlock:1.1.1
    container_name: interlock
    command: -D run
    ports:
      - 8080
    environment:
      INTERLOCK_CONFIG: |
        ListenAddr = ":8080"
        DockerURL = "unix:///var/run/docker.sock"
        TLSCACert = "/etc/docker/ca.pem"
        TLSCert = "/etc/docker/server.pem"
        TLSKey = "/etc/docker/server-key.pem"
        [[Extensions]]
        Name = "nginx"
        ConfigPath = "/etc/nginx/nginx.conf"
        PidPath = "/var/run/nginx.pid"
        TemplatePath = ""
        MaxConn = 1024
    volumes:
      - /etc/docker:/etc/docker:ro
      - /var/run/docker.sock:/var/run/docker.sock
    network_mode: bridge
    restart: always
  nginx:
    image: nginx
    container_name: nginx
    entrypoint: nginx
    command: -g "daemon off;" -c /etc/nginx/nginx.conf
    ports:
      - 80:80
    labels:
      - "interlock.ext.name=nginx"
    network_mode: bridge
    restart: always
  app:
    image: ehazlett/docker-demo
    container_name: app
    hostname: test.local
    ulimits:
      memlock: -1
    ports:
      - 8080
$ docker inspect app                                                                                                                                                                      [
    {
        "Id": "284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b",
        "Created": "2016-05-17T13:51:09.906017029Z",
        "Path": "/bin/docker-demo",
        "Args": [
            "-listen=:8080"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 9280,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-05-17T13:51:10.060165813Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:69b663051ba5740f495dc86f6eca34bc98f6704672298356bb200aea036e94bd",
        "ResolvConfPath": "/var/lib/docker/containers/284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b/hostname",
        "HostsPath": "/var/lib/docker/containers/284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b/hosts",
        "LogPath": "/var/lib/docker/containers/284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b/284032cb1fffa676fd382d252f2a5d0c8dbddbb9400737114a315fc870d84a1b-json.log",
        "Name": "/app",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "test2_default",
            "PortBindings": {
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": ""
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "StorageOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": [
                {
                    "Name": "memlock",
                    "Hard": -1,
                    "Soft": -1
                }
            ],
            "CpuCount": 0,
            "CpuPercent": 0,
            "BlkioIOps": 0,
            "BlkioBps": 0,
            "SandboxSize": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [],
        "Config": {
            "Hostname": "test",
            "Domainname": "local",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "-listen=:8080"
            ],
            "Image": "ehazlett/docker-demo",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/bin/docker-demo"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "a74c0dbc9be4e2b268244966f4d99e3fe0b47660424edcde7f84f2990cce0791",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "test2",
                "com.docker.compose.service": "app",
                "com.docker.compose.version": "1.7.0"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "2e81ad8e6a44ee396e618d5dbb0b3a27f352e707b316cfd593a14331c955bf62",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "8080/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "32809"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/2e81ad8e6a44",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "test2_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "app",
                        "284032cb1fff"
                    ],
                    "NetworkID": "5cc8abf32d129693cd4a7c846a423a32f0c8b93c52ea6c543f15ee6d41cd2e8b",
                    "EndpointID": "06cb88a36cdf04949ff6e287821ecc34e854810f2414d5e41fe902f885dcb61d",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02"
                }
            }
        }
    }
]

Loading Docker client from environment variables?

It would be nice if there was a method such as NewDockerClientEnv which automatically loaded the correct thing based on the environment variables such as DOCKER_HOST, DOCKER_CERT_PATH, etc. The code would be something like:

func NewDockerClientEnv() (*DockerClient, error) {
        tlsc := &tls.Config{}
        dockerCertPath := os.Getenv("DOCKER_CERT_PATH")

        cert, err := tls.LoadX509KeyPair(filepath.Join(dockerCertPath, "cert.pem"), filepath.Join(dockerCertPath, "key.pem"))
        if err != nil {
                return nil, fmt.Errorf("Error loading x509 key pair: %s", err)
        }

        tlsc.Certificates = append(tlsc.Certificates, cert)
        tlsc.InsecureSkipVerify = true

        dc, err := dockerclient.NewDockerClient(os.Getenv("DOCKER_HOST"), tlsc)
        if err != nil {
                return nil, fmt.Errorf("Error getting Docker Client: %s", err)
        }

        return dc, nil
}

I could submit a PR if there is interest. Interested?

golint

dockerclient should pass golint.

This is especially true since, being a library, it causes golint issues on projects importing it.

mock brings in testify which brings in httptest

MockClient depends on github.com/stretchr/testify/mock which depends on the standard library httptest package. This package defines a httptest.serve flag in the global flag set. Can the MockClient be in it's own package so only tests can import it so that flag doesn't show up in production binaries?

Indicate failure to pull an image

Currently the PullImage API doesn't indicate if there was an error while downloading an image.

Is it possible to parse the response of the remote api and return that image failed to download? I have seen other clients look for the presence of errorDetail in the response

Custom fields

I think we need to find a way to handle custom fields. For an example, docker swarm introduced some extra fields:

 ...
 "Node": {
        "ID": "IRHO:3ZO2:X25O:HODR:KLVC:E6RF:D5RW:Y4S5:XAGM:7NXU:YRLK:DOMM",
        "IP": "192.168.18.140",
        "Addr": "192.168.18.140:2375",
        "Name": "test.sample.com",
        "Cpus": 1,
        "Memory": 1034711040,
        "Labels": {
            "executiondriver": "native-0.2",
            "kernelversion": "3.13.0-32-generic",
            "operatingsystem": "Ubuntu 14.04.1 LTS",
            "region": "asia-sg",
            "storagedriver": "aufs"
        }
    },
...

Docker pkg/units moved

It appears that about an hour ago, docker decided to move pkg/units to pkg/go-units. See the PR here: https://github.com/docker/docker/pull/18682/files. This causes the below error when performing a "go get" on dockerclient.

github.com/samalba/dockerclient (download)
github.com/docker/docker (download)
package github.com/docker/docker/pkg/units: cannot find package "github.com/docker/docker/pkg/units" in any of:
    /usr/local/go/src/github.com/docker/docker/pkg/units (from $GOROOT)
    /go/src/github.com/docker/docker/pkg/units (from $GOPATH)

I believe that this line needs to be changed, but I am very new to Go so not 100% sure:

"github.com/docker/docker/pkg/units"

#202 breaks OS-X builds

#202 seems to break OSX builds:

$ go version
go version go1.5.1 darwin/amd64
$ go build
# github.com/samalba/dockerclient
could not determine kind of name for C.TCP_USER_TIMEOUT

Cut the dependency to docker/docker

It looks like using this library requires vendoring the entire docker/docker repo which is suboptimal.

The package is only uses the docker/docker repo in the following files:

types.go:

  • github.com/docker/docker/pkg/units: only for units.HumanDuration, actually the client should not tamper the results that are received from the API. I'm not sure why we're trying to produce strings like Exited %s ago in this repo... This is not docker cli.

engine_mock_test.go, dockerclient_test.go:

  • github.com/docker/docker/pkg/jsonlog: Just to construct a jsonlog-looking-like type. We can copy the type over here to do the same.
  • github.com/docker/docker/pkg/stdcopy: to do NewStdWriter, we can copy the logic here.
  • github.com/docker/docker/pkg/ioutils: uses NewFlushWriter, sounds like we can copy that here too.

What do maintainers think? I have a 60-line project that uses this samalba/dockerclient but I ended up vendoring 225,000+ lines of go code (only in docker/docker).

IMO we should cut the dependency to docker/docker ASAP.

Progress from calls such as PullImage

I'd like to print progress of the PullImage. I'm willing to do the PR but would like some guidance on the approach. Do we break the current API, new API? Does the API accept a chan and blocks, should it return immediatly and not block..... Just give me a method signature and I'll implement it :)

StartMonitorEvents is not idiomatic

StartMonitorEvents takes a callback, and a channel, and untyped args. It spins up a new goroutine per call, but shares an atomic to allow StopAllMonitorEvents to work. The whole thing just seems very messy.

https://github.com/go-fsnotify/fsnotify may be a good source of inspiration here.

Would prefer an API along the lines of:

type Watcher struct {
  Error chan error
  Event chan *Event
}

func (w *Watcher) Close() error {
  ...
}

func (d *DockerClient) Watcher() (*Watcher, error) {
}

The Start/Stop can go away. Internally a single HTTP stream can be used for all the Watchers. Each Watcher can provide a Close so a global Stop/Close isn't necessary.

Thoughts?

TestMonitorEvents is flaky

I ran the test suite a few times, and it seems like this test fails about half the time. From the test I can't exactly tell what it's expecting.

What is "more than 2 events" special? is 2 just an arbitrary guess at how many events will get in before the stop channel message gets through?

Why do we care if there are extra events?

support docker rm -v

I could definitely use support for the docker rm -v option to remove all volumes associated with the container. This is particularly useful when working with data volume containers over a remote connection.

Would you be willing to accept a pull request implementing this change? I was thinking something like the following:

-func RemoveContainer(id string, force bool)
+func RemoveContainer(id string, force, volumes bool)

Support Tags / Registry on Pull Image

Currently the dockerclient.PullImage only supports the name of the image and will always pull latest.
I might want to pull older versions in case a newer image is broken. Or i might want to pull from another Registry.

I can help look into this if you want.

Support attach / writing to stdin

It seems like the /attach/ endpoint is missing - filing a bug so I don't forget about this :)

Thanks for all your work, team!

๐Ÿ‘

Example for docker run -v and -e

I am looking for an example of using --volume with ContainerConfig. I see there is a Volumes map[string]struct{} in ContainerConfig, but how do I use it?

Also I can't find any example for using -e option. I have tried setting Env array item to be NAME=AJ. What should be the format for Env slice in ContainerConfig?

Events example using TLS for docker daemon

Hi,

I'm using Boot2Docker on a Mac which uses TLS. How do I configure the certificates for use with the client.

This is what I need to do using the python client.

tls_config = tls.TLSConfig(
client_cert=('cert.pem', 'key.pem'),
verify='ca.pem')

Also I'm getting an error when I run the events exampe.

./docker_evnts.go:44: reader declared and not used

Update Readme

The example is outdated

Also we need a maintainer section to do who to ping on an issue.

Document which version of Remote API is implemented in this library

For a visitor looking at this library I can't understand what version of Docker Remote API this package is compatible with or the minimum version it's supporting.

For instance, if a field is added to a type (that's cloned in types.go), I can't be sure if the field I'm looking at the latest Remote API docs would be returned or not.

I think a simple statement saying (I'm making up here)

This library is currently compatible with Docker Remote API 1.16.

would be really nice. As the author of .NET client library for Docker, I have a statement like:

[...] At the time of writing, it supports Docker Remote API v1.14.

in the README.md and it helps people running out into problems with not-yet-implemented in the client things.

A word on the README about the versioning would help here as well I guess.

Error when installing from go get github.com/samalba/dockerclient

go get github.com/samalba/dockerclient

Gives this error

# github.com/samalba/dockerclient
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:258: syntax error: unexpected range, expecting {
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:258: missing statement after label
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:261: syntax error: unexpected case, expecting semicolon or newline or }
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:267: syntax error: argument to go/defer must be function call
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:270: syntax error: unexpected }
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:272: non-declaration statement outside function body
/root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:273: syntax error: unexpected }
root@webserver:/etc/docker# /root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:258: syntax error: unexpected range, expecting {
bash: /root/gopath/src/github.com/samalba/dockerclient/dockerclient.go:258:: No such file or directory

Using go version go1.2.1 linux/amd64

boot2docker and TLS

Hi, Im getting the following error when connecting to docker (running with boot2docker on OSX) with dockerclient:

Get http://192.168.59.103:2376/v1.15/images/json: malformed HTTP response "\x15\x03\x01\x00\x02\x02". Are you trying to connect to a TLS-enabled daemon without TLS?

The docs at http://golang.org/pkg/crypto/tls/#Config don't really tell me how I should fill out the tls.Config structure to work with docker/boot2docker. Do you have any examples on how to do this?

Update API Version to 1.22

Corresponding with the Docker 1.10 release, we need to update API Version for dockerclient to 1.22. Creating this issue to track and discuss any changes that need to be made to support the updated API.

cc @dongluochen @vieux

Howto: Run an exec command on a running container

Hello, I'm trying to run a command on a running container. I'm not sure what I'm doing wrong. Could you assist. Running the test below returns the following:

vagrant@vagrant-ubuntu-trusty-64:~/go/src/com.stuff/ambassador$ go test -test.run TestExec -v=== RUN TestExec
dac07107d20a5834826f16547945d5afe6b714fcefe0820fd64e5ea8b27b1aaf
--- PASS: TestExec (0.01s)
PASS
func TestExec(t *testing.T) {
    //var sContainer dockerclient.Container
    var config dockerclient.ExecConfig
    containers, err := docker.ListContainers(true, false, "")
    if err != nil {
        t.Fatalf("cannot get containers: %s", err)
    }
    for _, c := range containers {
        for _, name := range c.Names {
            if name == "/testapi" {
                config.Container = c.Id
            }
        }
    }
    if config.Container == "" {
        t.Error("Container Not found")
    }
    config.Cmd = []string{"bash", "-c", "date"}
    config.AttachStdout = true
    config.AttachStderr = true
    config.AttachStdin = false
    config.Tty = false
    config.Detach = false
    ID, err := docker.ExecCreate(&config)
    fmt.Println(ID)
    if err != nil {
        t.Error(err)
    }

    config.Cmd = []string{}
    config.AttachStdout = true
    config.AttachStderr = true
    config.AttachStdin = true
    config.Tty = true
    config.Detach = true
    //fmt.Print(config)
    err = docker.ExecStart(ID, &config)
    if err != nil {
        t.Error(err)
    }

    //fmt.Print(containers)
}

How do I run a command and trap the response?

Fedora 25 - go test: ./dockerclient_test.go:286: invalid operation

cat /etc/redhat-release
#Fedora release 25 (Twenty Five)
dnf -y install "compiler(go-compiler)"

go version
#go version go1.7.5 linux/amd64

yum -y install "golang(github.com/docker/go-units)"
yum -y install "golang(github.com/stretchr/testify/mock)"
yum -y install "golang(github.com/docker/docker/pkg/ioutils)"
yum -y install "golang(golang.org/x/net/context)"
yum -y install "golang(github.com/Sirupsen/logrus)"
yum -y install "golang(github.com/gorilla/mux)"

rm -rf /tmp/go
mkdir -p /tmp/go/src
export GOPATH=/tmp/go:/usr/share/gocode
cd /tmp/go/src
mkdir -p github.com/samalba
cd github.com/samalba
git clone https://github.com/samalba/dockerclient
cd dockerclient
git rev-parse HEAD
#a3036261847103270e9f732509f43b5f98710ace
go test
#./dockerclient_test.go:286: invalid operation: eventInfo.Event != expectedEvents[0] (struct containing Actor cannot be compared)
#./dockerclient_test.go:306: invalid operation: eventInfo.Event != expectedEvent (struct containing Actor cannot be compared)
#FAIL   github.com/samalba/dockerclient [build failed]

Version to Avoid Breaking API Changes

Lately there have been a number of changes which have broken this library's API. This has affected my project, Beacon, and its users. Short of compiling my own project on a daily basis there's no way to get notified when changes occur.

I'm proposing that semantic versioning be implemented and a service such as gopkg.in be used so that API changes do not break existing packages.

Thanks.

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.