1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
docker_client.go 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
David Gageot 提交于 2016-01-04 09:08 . FIX #2703 Update dockerclient
package mcndockerclient
import (
"fmt"
"github.com/docker/machine/libmachine/cert"
"github.com/samalba/dockerclient"
)
// DockerClient creates a docker client for a given host.
func DockerClient(dockerHost DockerHost) (*dockerclient.DockerClient, error) {
url, err := dockerHost.URL()
if err != nil {
return nil, err
}
tlsConfig, err := cert.ReadTLSConfig(url, dockerHost.AuthOptions())
if err != nil {
return nil, fmt.Errorf("Unable to read TLS config: %s", err)
}
return dockerclient.NewDockerClient(url, tlsConfig)
}
// CreateContainer creates a docker container.
func CreateContainer(dockerHost DockerHost, config *dockerclient.ContainerConfig, name string) error {
docker, err := DockerClient(dockerHost)
if err != nil {
return err
}
if err = docker.PullImage(config.Image, nil); err != nil {
return fmt.Errorf("Unable to pull image: %s", err)
}
var authConfig *dockerclient.AuthConfig
containerID, err := docker.CreateContainer(config, name, authConfig)
if err != nil {
return fmt.Errorf("Error while creating container: %s", err)
}
if err = docker.StartContainer(containerID, &config.HostConfig); err != nil {
return fmt.Errorf("Error while starting container: %s", err)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.15.0-rancher9

搜索帮助

0d507c66 1850385 C8b1a773 1850385