Browse code

Add a README to the client's package…

… taken from the old engine-api project.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/09/12 18:41:11
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+## Client
1
+
2
+The client package implements a fully featured http client to interact with the Docker engine. It's modeled after the requirements of the Docker engine CLI, but it can also serve other purposes.
3
+
4
+### Usage
5
+
6
+You can use this client package in your applications by creating a new client object. Then use that object to execute operations against the remote server. Follow the example below to see how to list all the containers running in a Docker engine host:
7
+
8
+```go
9
+package main
10
+
11
+import (
12
+	"fmt"
13
+
14
+	"github.com/docker/docker/client"
15
+	"github.com/docker/docker/api/types"
16
+	"golang.org/x/net/context"
17
+)
18
+
19
+func main() {
20
+	defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
21
+	cli, err := client.NewClient("unix:///var/run/docker.sock", "v1.22", nil, defaultHeaders)
22
+	if err != nil {
23
+		panic(err)
24
+	}
25
+
26
+	options := types.ContainerListOptions{All: true}
27
+	containers, err := cli.ContainerList(context.Background(), options)
28
+	if err != nil {
29
+		panic(err)
30
+	}
31
+
32
+	for _, c := range containers {
33
+		fmt.Println(c.ID)
34
+	}
35
+}
36
+```