Skip to content

Commit

Permalink
Merge pull request #83 from pmenglund/docker-machine
Browse files Browse the repository at this point in the history
core: add support to connect to docker-machine
  • Loading branch information
arekkas committed Feb 24, 2017
2 parents 6f03cce + 8ea2c2d commit 0944e3b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dockertest.go
Expand Up @@ -2,12 +2,13 @@ package dockertest

import (
"fmt"
"os"
"runtime"
"time"

"github.com/cenk/backoff"
dc "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
"time"
"runtime"
"os"
)

// Pool represents a connection to the docker API and is used to create and remove docker images.
Expand Down Expand Up @@ -57,11 +58,19 @@ func NewTLSPool(endpoint, certpath string) (*Pool, error) {
}

// NewPool creates a new pool. You can pass an empty string to use the default, which is taken from the environment
// variable DOCKER_URL or if that is not defined a sensible default for the operating system you are on.
// variable DOCKER_URL, or from docker-machine if the environment variable DOCKER_MACHINE_NAME is set,
// or if neither is defined a sensible default for the operating system you are on.
func NewPool(endpoint string) (*Pool, error) {
if endpoint == "" {
if os.Getenv("DOCKER_URL") != "" {
endpoint = os.Getenv("DOCKER_URL")
} else if os.Getenv("DOCKER_MACHINE_NAME") != "" {
client, err := dc.NewClientFromEnv()
if err != nil {
return nil, errors.Wrap(err, "")
}

return &Pool{Client: client}, nil
} else if runtime.GOOS == "windows" {
endpoint = "http://localhost:2375"
} else {
Expand Down Expand Up @@ -124,7 +133,6 @@ func (d *Pool) Run(repository, tag string, env []string) (*Resource, error) {
}, nil
}


// Purge removes a container and linked volumes from docker.
func (d *Pool) Purge(r *Resource) error {
if err := d.Client.KillContainer(dc.KillContainerOptions{ID: r.Container.ID}); err != nil {
Expand Down

0 comments on commit 0944e3b

Please sign in to comment.