Skip to content

Commit

Permalink
docker api enforces tls from docker 1.13 onwards (#80)
Browse files Browse the repository at this point in the history
* docker api enforces tls from docker 1.13 onwards

For docker 1.13 onwards, not using `dc.NewTLSClient` will fail with malformed http response.

Also, is there an option in dockertest v3 to support docker-machine? There was an option to support docker-machine in v2 but I can't seem to find it in v3. Providing such an option will allow us to use `dc.NewClientFromEnv()`.

* `NewTLSPool` for TLS endpoints

* NewClient vs NewTLSClient
  • Loading branch information
calvinchengx authored and arekkas committed Feb 24, 2017
1 parent 0a82db1 commit 6f03cce
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ func (r *Resource) GetPort(id string) string {
return m[0].HostPort
}

// NewTLSPool creates a new pool given an endpoint and the certificate path. This is required for endpoints that
// require TLS communication.
func NewTLSPool(endpoint, certpath string) (*Pool, error) {
ca := fmt.Sprintf("%s/ca.pem", certpath)
cert := fmt.Sprintf("%s/cert.pem", certpath)
key := fmt.Sprintf("%s/key.pem", certpath)

client, err := dc.NewTLSClient(endpoint, cert, key, ca)
if err != nil {
return nil, errors.Wrap(err, "")
}

return &Pool{
Client: client,
}, nil
}

// 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.
func NewPool(endpoint string) (*Pool, error) {
Expand All @@ -51,7 +68,7 @@ func NewPool(endpoint string) (*Pool, error) {
endpoint = "unix:///var/run/docker.sock"
}
}

client, err := dc.NewClient(endpoint)
if err != nil {
return nil, errors.Wrap(err, "")
Expand Down

0 comments on commit 6f03cce

Please sign in to comment.