Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Loading Docker client from environment variables? #161

Open
nathanleclaire opened this issue Sep 11, 2015 · 1 comment
Open

Loading Docker client from environment variables? #161

nathanleclaire opened this issue Sep 11, 2015 · 1 comment

Comments

@nathanleclaire
Copy link

It would be nice if there was a method such as NewDockerClientEnv which automatically loaded the correct thing based on the environment variables such as DOCKER_HOST, DOCKER_CERT_PATH, etc. The code would be something like:

func NewDockerClientEnv() (*DockerClient, error) {
        tlsc := &tls.Config{}
        dockerCertPath := os.Getenv("DOCKER_CERT_PATH")

        cert, err := tls.LoadX509KeyPair(filepath.Join(dockerCertPath, "cert.pem"), filepath.Join(dockerCertPath, "key.pem"))
        if err != nil {
                return nil, fmt.Errorf("Error loading x509 key pair: %s", err)
        }

        tlsc.Certificates = append(tlsc.Certificates, cert)
        tlsc.InsecureSkipVerify = true

        dc, err := dockerclient.NewDockerClient(os.Getenv("DOCKER_HOST"), tlsc)
        if err != nil {
                return nil, fmt.Errorf("Error getting Docker Client: %s", err)
        }

        return dc, nil
}

I could submit a PR if there is interest. Interested?

@keegancsmith
Copy link
Contributor

I submitted #201 which does a part of this. For an example usage check out https://github.com/drone/drone-exec/pull/13
I can flesh out that PR further by adding a NewDockerClientEnv, but to match the same functionality as the official docker client is a bit more work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants