client.go 643 B

12345678910111213141516171819202122232425262728293031
  1. package docker
  2. import (
  3. "github.com/rancher/os/config"
  4. dockerClient "github.com/docker/engine-api/client"
  5. "golang.org/x/net/context"
  6. )
  7. func NewSystemClient() (dockerClient.APIClient, error) {
  8. return NewClient(config.SystemDockerHost)
  9. }
  10. func NewDefaultClient() (dockerClient.APIClient, error) {
  11. return NewClient(config.DockerHost)
  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. }