当前位置: 首页>>代码示例>>Golang>>正文


Golang go-dockerclient.NewClientFromEnv函数代码示例

本文整理汇总了Golang中github.com/fsouza/go-dockerclient.NewClientFromEnv函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClientFromEnv函数的具体用法?Golang NewClientFromEnv怎么用?Golang NewClientFromEnv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClientFromEnv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: dockerClients

// dockerClients creates two *docker.Client, one for long running operations and
// the other for shorter operations. In test / dev mode we can use ENV vars to
// connect to the docker daemon. In production mode we will read docker.endpoint
// from the config file.
func (d *DockerDriver) dockerClients() (*docker.Client, *docker.Client, error) {
	if client != nil && waitClient != nil {
		return client, waitClient, nil
	}

	var err error
	var merr multierror.Error
	createClients.Do(func() {
		if err = shelpers.Init(); err != nil {
			d.logger.Printf("[FATAL] driver.docker: unable to initialize stats: %v", err)
			return
		}

		// Default to using whatever is configured in docker.endpoint. If this is
		// not specified we'll fall back on NewClientFromEnv which reads config from
		// the DOCKER_* environment variables DOCKER_HOST, DOCKER_TLS_VERIFY, and
		// DOCKER_CERT_PATH. This allows us to lock down the config in production
		// but also accept the standard ENV configs for dev and test.
		dockerEndpoint := d.config.Read("docker.endpoint")
		if dockerEndpoint != "" {
			cert := d.config.Read("docker.tls.cert")
			key := d.config.Read("docker.tls.key")
			ca := d.config.Read("docker.tls.ca")

			if cert+key+ca != "" {
				d.logger.Printf("[DEBUG] driver.docker: using TLS client connection to %s", dockerEndpoint)
				client, err = docker.NewTLSClient(dockerEndpoint, cert, key, ca)
			} else {
				d.logger.Printf("[DEBUG] driver.docker: using standard client connection to %s", dockerEndpoint)
				client, err = docker.NewClient(dockerEndpoint)
			}
			client.HTTPClient.Timeout = dockerTimeout
			return
		}

		d.logger.Println("[DEBUG] driver.docker: using client connection initialized from environment")
		client, err = docker.NewClientFromEnv()
		if err != nil {
			merr.Errors = append(merr.Errors, err)
		}
		client.HTTPClient.Timeout = dockerTimeout

		waitClient, err = docker.NewClientFromEnv()
		if err != nil {
			merr.Errors = append(merr.Errors, err)
		}
	})
	return client, waitClient, merr.ErrorOrNil()
}
开发者ID:tbartelmess,项目名称:nomad,代码行数:53,代码来源:docker.go

示例2: dockerClient

// dockerClient creates *docker.Client. In test / dev mode we can use ENV vars
// to connect to the docker daemon. In production mode we will read
// docker.endpoint from the config file.
func (d *DockerDriver) dockerClient() (*docker.Client, error) {
	if client != nil {
		return client, nil
	}

	var err error
	createClient.Do(func() {
		// Default to using whatever is configured in docker.endpoint. If this is
		// not specified we'll fall back on NewClientFromEnv which reads config from
		// the DOCKER_* environment variables DOCKER_HOST, DOCKER_TLS_VERIFY, and
		// DOCKER_CERT_PATH. This allows us to lock down the config in production
		// but also accept the standard ENV configs for dev and test.
		dockerEndpoint := d.config.Read("docker.endpoint")
		if dockerEndpoint != "" {
			cert := d.config.Read("docker.tls.cert")
			key := d.config.Read("docker.tls.key")
			ca := d.config.Read("docker.tls.ca")

			if cert+key+ca != "" {
				d.logger.Printf("[DEBUG] driver.docker: using TLS client connection to %s", dockerEndpoint)
				client, err = docker.NewTLSClient(dockerEndpoint, cert, key, ca)
			} else {
				d.logger.Printf("[DEBUG] driver.docker: using standard client connection to %s", dockerEndpoint)
				client, err = docker.NewClient(dockerEndpoint)
			}
			return
		}

		d.logger.Println("[DEBUG] driver.docker: using client connection initialized from environment")
		client, err = docker.NewClientFromEnv()
	})
	return client, err
}
开发者ID:stigkj,项目名称:nomad,代码行数:36,代码来源:docker.go

示例3: init

func init() {
	var err error
	Client, err = docker.NewClientFromEnv()
	if err != nil {
		panic(err)
	}
}
开发者ID:telamon,项目名称:wharfmaster,代码行数:7,代码来源:service.go

示例4: Complete

func (o *DockerbuildOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
	paths, envArgs, ok := cmdutil.SplitEnvironmentFromResources(args)
	if !ok {
		return kcmdutil.UsageError(cmd, "context directory must be specified before environment changes: %s", strings.Join(args, " "))
	}
	if len(paths) != 2 {
		return kcmdutil.UsageError(cmd, "the directory to build and tag must be specified")
	}
	o.Arguments, _, _ = cmdutil.ParseEnvironmentArguments(envArgs)
	o.Directory = paths[0]
	o.Tag = paths[1]
	if len(o.DockerfilePath) == 0 {
		o.DockerfilePath = filepath.Join(o.Directory, "Dockerfile")
	}

	var mounts []dockerbuilder.Mount
	for _, s := range o.MountSpecs {
		segments := strings.Split(s, ":")
		if len(segments) != 2 {
			return kcmdutil.UsageError(cmd, "--mount must be of the form SOURCE:DEST")
		}
		mounts = append(mounts, dockerbuilder.Mount{SourcePath: segments[0], DestinationPath: segments[1]})
	}
	o.Mounts = mounts

	client, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}
	o.Client = client

	o.Keyring = credentialprovider.NewDockerKeyring()

	return nil
}
开发者ID:abhgupta,项目名称:origin,代码行数:35,代码来源:dockerbuild.go

示例5: dockerSetup

// dockerSetup does all of the basic setup you need to get a running docker
// process up and running for testing. Use like:
//
//	task := taskTemplate()
//	// do custom task configuration
//	client, handle, cleanup := dockerSetup(t, task)
//	defer cleanup()
//	// do test stuff
//
// If there is a problem during setup this function will abort or skip the test
// and indicate the reason.
func dockerSetup(t *testing.T, task *structs.Task) (*docker.Client, DriverHandle, func()) {
	if !testutil.DockerIsConnected(t) {
		t.SkipNow()
	}

	client, err := docker.NewClientFromEnv()
	if err != nil {
		t.Fatalf("Failed to initialize client: %s\nStack\n%s", err, debug.Stack())
	}

	driverCtx, execCtx := testDriverContexts(task)
	driver := NewDockerDriver(driverCtx)

	handle, err := driver.Start(execCtx, task)
	if err != nil {
		execCtx.AllocDir.Destroy()
		t.Fatalf("Failed to start driver: %s\nStack\n%s", err, debug.Stack())
	}
	if handle == nil {
		execCtx.AllocDir.Destroy()
		t.Fatalf("handle is nil\nStack\n%s", debug.Stack())
	}

	cleanup := func() {
		handle.Kill()
		execCtx.AllocDir.Destroy()
	}

	return client, handle, cleanup
}
开发者ID:hooklift,项目名称:nomad,代码行数:41,代码来源:docker_test.go

示例6: getDockerClient

// Get a *docker.Client, either using the endpoint passed in, or using
// DOCKER_HOST, DOCKER_TLS_VERIFY, and DOCKER_CERT path per their spec
func getDockerClient(dockerEndpoint string) (*docker.Client, error) {
	if len(dockerEndpoint) > 0 {
		glog.Infof("Connecting to docker on %s", dockerEndpoint)
		return docker.NewClient(dockerEndpoint)
	}
	return docker.NewClientFromEnv()
}
开发者ID:johndmulhausen,项目名称:kubernetes,代码行数:9,代码来源:docker.go

示例7: checkDockerVersion

func checkDockerVersion() error {
	startCheck("Docker up to date")
	dockerVersionTest, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}

	minDockerVersion, err := docker.NewAPIVersion("1.9")
	e, err := dockerVersionTest.Version()
	if err != nil {
		return err
	}

	currentVersionParts := strings.Split(e.Get("Version"), ".")
	currentVersion, err := docker.NewAPIVersion(fmt.Sprintf("%s.%s", currentVersionParts[0], currentVersionParts[1]))
	if err != nil {
		return err
	}

	if !(currentVersion.GreaterThanOrEqualTo(minDockerVersion)) {
		diagnose(Diagnosis{
			Title:       "Docker up to date",
			Description: "<fail>Docker engine is out of date (min: 1.9)</fail>",
			DocsLink:    "https://docs.docker.com/engine/installation/",
			Kind:        "fail",
		})
	} else {
		diagnose(Diagnosis{
			Title: "Docker up to date",
			Kind:  "success",
		})
	}
	return nil
}
开发者ID:convox,项目名称:rack,代码行数:34,代码来源:doctor.go

示例8: TestConformanceInternal

// TestConformance* compares the result of running the direct build against a
// sequential docker build. A dockerfile and git repo is loaded, then each step
// in the file is run sequentially, committing after each step. The generated
// image.Config and the resulting filesystems are compared. The next step reuses
// the previously generated layer and performs an incremental diff. This ensures
// that each step is functionally equivalent.
//
// Deviations:
// * Builds run at different times
//   * Modification timestamps are ignored on files
//   * Some processes (gem install) result in files created in the image that
//     have different content because of that (timestamps in files). We treat
//     a file that is identical except for size within 10 bytes and neither old
//     or new is zero bytes to be identical.
// * Docker container commit with ENV FOO=BAR and a Docker build with line
//   ENV FOO=BAR will generate an image with FOO=BAR in different positions
//   (commit places the variable first, build: last). We try to align the
//   generated environment variable to ensure they are equal.
// * The parent image ID is ignored.
//
// TODO: .dockerignore
// TODO: check context dir
// TODO: ONBUILD
// TODO: ensure that the final built image has the right UIDs
//
func TestConformanceInternal(t *testing.T) {
	testCases := []conformanceTest{
		{
			ContextDir: "fixtures/dir",
		},
		// TODO: Fix this test
		// {
		// 	ContextDir: "fixtures/ignore",
		// },
		{
			Dockerfile: "fixtures/Dockerfile.env",
		},
		{
			Dockerfile: "fixtures/Dockerfile.edgecases",
		},
		{
			Dockerfile: "fixtures/Dockerfile.exposedefault",
		},
		{
			Dockerfile: "fixtures/Dockerfile.add",
		},
	}

	c, err := docker.NewClientFromEnv()
	if err != nil {
		t.Fatal(err)
	}

	for i, test := range testCases {
		conformanceTester(t, c, test, i, *compareLayers)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:57,代码来源:conformance_test.go

示例9: Ping

// Ping implements the DockerInterface Ping method.
func (c *KubeDocker) Ping() error {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		return err
	}
	return client.Ping()
}
开发者ID:Xmagicer,项目名称:origin,代码行数:8,代码来源:docker.go

示例10: worker

func worker(requests int, image string, completeCh chan time.Duration) {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		panic(err)
	}

	for i := 0; i < requests; i++ {
		start := time.Now()

		container, err := client.CreateContainer(docker.CreateContainerOptions{
			Config: &docker.Config{
				Image: image,
			}})
		if err != nil {
			panic(err)
		}

		err = client.StartContainer(container.ID, nil)
		if err != nil {
			panic(err)
		}

		completeCh <- time.Since(start)
	}
}
开发者ID:vieux,项目名称:swarm-bench,代码行数:25,代码来源:main.go

示例11: DockerClient

// DockerClient creates a docker client from environment
func DockerClient() *dockerclient.Client {
	client, err := dockerclient.NewClientFromEnv()
	if err != nil {
		log.Fatalf("Unabled to create a Docker Client: Is Docker Machine installed and running?")
	}
	client.SkipServerVersionCheck = true
	return client
}
开发者ID:mefellows,项目名称:parity,代码行数:9,代码来源:utils.go

示例12: ClientOrDie

// ClientOrDie creates a new Docker client. If one couldn't be created, logs and error and exits with status code 1
func ClientOrDie() *docker.Client {
	cl, err := docker.NewClientFromEnv()
	if err != nil {
		log.Err("creating new docker client (%s)", err)
		os.Exit(1)
	}
	return cl
}
开发者ID:arschles,项目名称:gci,代码行数:9,代码来源:client.go

示例13: NewControllerFromEnv

// NewControllerFromEnv creates a new Docker client using environment clues.
func NewControllerFromEnv(out io.Writer) (*Controller, error) {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		return nil, fmt.Errorf("could not create Docker client: %v", err)
	}

	return NewController(client, out)
}
开发者ID:redspread,项目名称:spread,代码行数:9,代码来源:controller.go

示例14: NewDockerClient

func NewDockerClient() (*docker.Client, error) {
	host := os.Getenv("DOCKER_HOST")
	hostIsLocal := host == "" || strings.HasPrefix(host, "unix://")
	if !hostIsLocal {
		log.Warnf("Detected DOCKER_HOST %s. This should not be remote.",
			host)
	}
	return docker.NewClientFromEnv()
}
开发者ID:terminiter,项目名称:earthquake,代码行数:9,代码来源:util.go

示例15: GetClient

// GetClient returns a valid Docker client, the address of the client, or an error
// if the client couldn't be created.
func (_ *Helper) GetClient() (client *docker.Client, endpoint string, err error) {
	client, err = docker.NewClientFromEnv()
	if len(os.Getenv("DOCKER_HOST")) > 0 {
		endpoint = os.Getenv("DOCKER_HOST")
	} else {
		endpoint = "unix:///var/run/docker.sock"
	}
	return
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:docker.go


注:本文中的github.com/fsouza/go-dockerclient.NewClientFromEnv函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。