本文整理汇总了Golang中github.com/samalba/dockerclient.Client.CreateContainer方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.CreateContainer方法的具体用法?Golang Client.CreateContainer怎么用?Golang Client.CreateContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/samalba/dockerclient.Client
的用法示例。
在下文中一共展示了Client.CreateContainer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunDaemon
// RunDaemon creates the docker container, pulling images if necessary, starts
// the container and returns the container information. It does not wait for
// the container to exit.
func RunDaemon(client dockerclient.Client, conf *dockerclient.ContainerConfig, name string) (*dockerclient.ContainerInfo, error) {
// attempts to create the contianer
id, err := client.CreateContainer(conf, name)
if err != nil {
// and pull the image and re-create if that fails
err = client.PullImage(conf.Image, nil)
if err != nil {
return nil, err
}
id, err = client.CreateContainer(conf, name)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
}
// fetches the container information
info, err := client.InspectContainer(id)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
// starts the container
err = client.StartContainer(id, &conf.HostConfig)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
return info, err
}
示例2: createContainer
// createContainer creates a new container using the specified options. Per the
// docker API, the created container is not running and must be started
// explicitly.
func createContainer(client dockerclient.Client, config dockerclient.ContainerConfig) (*Container, error) {
id, err := client.CreateContainer(&config, "")
if err != nil {
return nil, err
}
return &Container{
ID: id,
containerInfo: dockerclient.ContainerInfo{Id: id},
client: client}, nil
}
示例3: Create
// Create a container
func Create(docker dockerclient.Client, name string, image string) string {
// Create a container
containerConfig := &dockerclient.ContainerConfig{
Image: image,
// Cmd: []string{"bash"},
AttachStdin: true,
Tty: true}
id, err := docker.CreateContainer(containerConfig, name)
if err != nil {
log.Fatal(err)
}
return id
}
示例4: Start
func Start(client dockerclient.Client, conf *dockerclient.ContainerConfig, auth *dockerclient.AuthConfig, pull bool) (*dockerclient.ContainerInfo, error) {
// force-pull the image if specified.
if pull {
log.Printf("Pulling image %s", conf.Image)
client.PullImage(conf.Image, auth)
}
// attempts to create the contianer
id, err := client.CreateContainer(conf, "", auth)
if err != nil {
log.Printf("Pulling image %s", conf.Image)
// and pull the image and re-create if that fails
err = client.PullImage(conf.Image, auth)
if err != nil {
log.Errorf("Error pulling %s. %s\n", conf.Image, err)
return nil, err
}
id, err = client.CreateContainer(conf, "", auth)
if err != nil {
log.Errorf("Error creating %s. %s\n", conf.Image, err)
client.RemoveContainer(id, true, true)
return nil, err
}
}
// fetches the container information
info, err := client.InspectContainer(id)
if err != nil {
log.Errorf("Error inspecting %s. %s\n", conf.Image, err)
client.RemoveContainer(id, true, true)
return nil, err
}
// starts the container
err = client.StartContainer(id, &conf.HostConfig)
if err != nil {
log.Errorf("Error starting %s. %s\n", conf.Image, err)
}
return info, err
}