1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
docker.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
Kunal Kushwaha 提交于 2015-11-27 17:48 . Host provisioing using Docker API
package provision
import (
"fmt"
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/mcndockerclient"
"github.com/samalba/dockerclient"
)
// DockerClient implements DockerHost(mcndockerclient) interface
type DockerClient struct {
HostURL string
AuthOption auth.Options
}
// URL returns the Docker host URL
func (dc DockerClient) URL() (string, error) {
if dc.HostURL == "" {
return "", fmt.Errorf("Docker Host URL not set")
}
return dc.HostURL, nil
}
// AuthOptions returns the authOptions
func (dc DockerClient) AuthOptions() *auth.Options {
return &dc.AuthOption
}
//CreateContainer creates a docker container.
func CreateContainer(dockerHost DockerClient, config *dockerclient.ContainerConfig, name string) error {
docker, err := mcndockerclient.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)
}
containerID, err := docker.CreateContainer(config, name)
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.5.4

搜索帮助