forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.go
39 lines (29 loc) · 1.03 KB
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package util
import (
"os"
dockerClient "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
)
const defaultDockerEndpoint = "unix:///var/run/docker.sock"
// RequireDocker ensures that a new docker client can be created and that a ListImages command can be run on the client
// or it fails with glog.Fatal
func RequireDocker() {
client, err := NewDockerClient()
if err != nil {
glog.Fatalf("unable to create docker client for testing: %v", err)
}
//simple test to make sure you can take action with the client
_, err = client.ListImages(dockerClient.ListImagesOptions{All: false})
if err != nil {
glog.Fatalf("unable to create docker client for testing: %v", err)
}
}
// newDockerClient creates a docker client using the env var DOCKER_ENDPOINT or, if not supplied, uses the default
// docker endpoint /var/run/docker.sock
func NewDockerClient() (*dockerClient.Client, error) {
endpoint := os.Getenv("DOCKER_ENDPOINT")
if len(endpoint) == 0 {
endpoint = defaultDockerEndpoint
}
return dockerClient.NewClient(endpoint)
}