forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.go
29 lines (23 loc) · 882 Bytes
/
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
package util
import (
dockerClient "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
)
// 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) {
return dockerClient.NewClientFromEnv()
}