Skip to content

Instantly share code, notes, and snippets.

@kuninori
Last active August 29, 2015 14:12
Show Gist options
  • Save kuninori/452cd4c32805c056aee7 to your computer and use it in GitHub Desktop.
Save kuninori/452cd4c32805c056aee7 to your computer and use it in GitHub Desktop.
Access to Docker API on boot2docker using dockerclient
package main
import (
"github.com/samalba/dockerclient"
"fmt"
"crypto/tls"
"crypto/x509"
"io/ioutil"
)
func main() {
// TLS is required.
caPath := "/Users/kuninori/.boot2docker/certs/boot2docker-vm/ca.pem"
certPath := "/Users/kuninori/.boot2docker/certs/boot2docker-vm/cert.pem"
keyPath := "/Users/kuninori/.boot2docker/certs/boot2docker-vm/key.pem"
cert, _ := tls.LoadX509KeyPair(certPath, keyPath)
pem, _ := ioutil.ReadFile(caPath)
cfg := &tls.Config{
RootCAs: x509.NewCertPool(),
ClientAuth: tls.RequireAndVerifyClientCert,
Certificates: []tls.Certificate{cert},
}
cfg.RootCAs.AppendCertsFromPEM(pem)
docker, _ := dockerclient.NewDockerClient("tcp://192.168.59.103:2376", cfg)
containers, err := docker.ListContainers(true, true, "")
if err != nil {
fmt.Printf("error:%", err)
return
}
for _, c := range containers{
fmt.Printf("container id: å%s\n", c.Id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment