README.markdown
1# go-dockerclient
2
3[![Travis Build Status](https://travis-ci.org/fsouza/go-dockerclient.svg?branch=master)](https://travis-ci.org/fsouza/go-dockerclient)
4[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/4m374pti06ubg2l7?svg=true)](https://ci.appveyor.com/project/fsouza/go-dockerclient)
5[![GoDoc](https://img.shields.io/badge/api-Godoc-blue.svg?style=flat-square)](https://godoc.org/github.com/fsouza/go-dockerclient)
6
7This package presents a client for the Docker remote API. It also provides
8support for the extensions in the [Swarm API](https://docs.docker.com/swarm/swarm-api/).
9
10This package also provides support for docker's network API, which is a simple
11passthrough to the libnetwork remote API. Note that docker's network API is
12only available in docker 1.8 and above, and only enabled in docker if
13DOCKER_EXPERIMENTAL is defined during the docker build process.
14
15For more details, check the [remote API
16documentation](http://docs.docker.com/engine/reference/api/docker_remote_api/).
17
18## Example
19
20```go
21package main
22
23import (
24 "fmt"
25
26 "github.com/fsouza/go-dockerclient"
27)
28
29func main() {
30 endpoint := "unix:///var/run/docker.sock"
31 client, err := docker.NewClient(endpoint)
32 if err != nil {
33 panic(err)
34 }
35 imgs, err := client.ListImages(docker.ListImagesOptions{All: false})
36 if err != nil {
37 panic(err)
38 }
39 for _, img := range imgs {
40 fmt.Println("ID: ", img.ID)
41 fmt.Println("RepoTags: ", img.RepoTags)
42 fmt.Println("Created: ", img.Created)
43 fmt.Println("Size: ", img.Size)
44 fmt.Println("VirtualSize: ", img.VirtualSize)
45 fmt.Println("ParentId: ", img.ParentID)
46 }
47}
48```
49
50## Using with TLS
51
52In order to instantiate the client for a TLS-enabled daemon, you should use
53NewTLSClient, passing the endpoint and path for key and certificates as
54parameters.
55
56```go
57package main
58
59import (
60 "fmt"
61
62 "github.com/fsouza/go-dockerclient"
63)
64
65func main() {
66 endpoint := "tcp://[ip]:[port]"
67 path := os.Getenv("DOCKER_CERT_PATH")
68 ca := fmt.Sprintf("%s/ca.pem", path)
69 cert := fmt.Sprintf("%s/cert.pem", path)
70 key := fmt.Sprintf("%s/key.pem", path)
71 client, _ := docker.NewTLSClient(endpoint, cert, key, ca)
72 // use client
73}
74```
75
76If using [docker-machine](https://docs.docker.com/machine/), or another
77application that exports environment variables `DOCKER_HOST`,
78`DOCKER_TLS_VERIFY`, `DOCKER_CERT_PATH`, you can use NewClientFromEnv.
79
80
81```go
82package main
83
84import (
85 "fmt"
86
87 "github.com/fsouza/go-dockerclient"
88)
89
90func main() {
91 client, _ := docker.NewClientFromEnv()
92 // use client
93}
94```
95
96See the documentation for more details.
97
98## Developing
99
100All development commands can be seen in the [Makefile](Makefile).
101
102Commited code must pass:
103
104* [golint](https://github.com/golang/lint) (with some exceptions, see the Makefile).
105* [go vet](https://golang.org/cmd/vet/)
106* [gofmt](https://golang.org/cmd/gofmt)
107* [go test](https://golang.org/cmd/go/#hdr-Test_packages)
108
109Running `make test` will check all of these. If your editor does not
110automatically call ``gofmt -s``, `make fmt` will format all go files in this
111repository.
112
113## Vendoring
114
115go-dockerclient uses [dep](https://github.com/golang/dep/) for vendoring. If
116you're using dep, you should be able to pick go-dockerclient releases and get
117the proper dependencies.
118
119With other vendoring tools, users might need to specify go-dockerclient's
120dependencies manually.
121
122## Using with Docker 1.9 and Go 1.4
123
124There's a tag for using go-dockerclient with Docker 1.9 (which requires
125compiling go-dockerclient with Go 1.4), the tag name is ``docker-1.9/go-1.4``.
126
127The instructions below can be used to get a version of go-dockerclient that compiles with Go 1.4:
128
129```
130% git clone -b docker-1.9/go-1.4 https://github.com/fsouza/go-dockerclient.git $GOPATH/src/github.com/fsouza/go-dockerclient
131% git clone -b v1.9.1 https://github.com/docker/docker.git $GOPATH/src/github.com/docker/docker
132% go get github.com/fsouza/go-dockerclient
133```
134