client.go 645 B

123456789101112131415161718192021222324252627282930
  1. package docker
  2. import (
  3. dockerClient "github.com/docker/engine-api/client"
  4. "github.com/rancher/os/config"
  5. "golang.org/x/net/context"
  6. )
  7. func NewSystemClient() (dockerClient.APIClient, error) {
  8. return NewClient(config.DOCKER_SYSTEM_HOST)
  9. }
  10. func NewDefaultClient() (dockerClient.APIClient, error) {
  11. return NewClient(config.DOCKER_HOST)
  12. }
  13. func NewClient(endpoint string) (dockerClient.APIClient, error) {
  14. client, err := dockerClient.NewClient(endpoint, "", nil, nil)
  15. if err != nil {
  16. return nil, err
  17. }
  18. err = ClientOK(endpoint, func() bool {
  19. _, err := client.Info(context.Background())
  20. return err == nil
  21. })
  22. return client, err
  23. }