本文整理匯總了Golang中github.com/docker/swarm/cluster.Engine.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.Create方法的具體用法?Golang Engine.Create怎麽用?Golang Engine.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarm/cluster.Engine
的用法示例。
在下文中一共展示了Engine.Create方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createContainer
func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string, withSoftImageAffinity bool) (*cluster.Container, error) {
c.scheduler.Lock()
defer c.scheduler.Unlock()
// Ensure the name is available
if cID := c.getIDFromName(name); cID != "" {
return nil, fmt.Errorf("Conflict, The name %s is already assigned to %s. You have to delete (or rename) that container to be able to assign %s to a container again.", name, cID, name)
}
// Associate a Swarm ID to the container we are creating.
config.SetSwarmID(c.generateUniqueID())
configTemp := config
if withSoftImageAffinity {
configTemp.AddAffinity("image==~" + config.Image)
}
n, err := c.scheduler.SelectNodeForContainer(c.listNodes(), configTemp)
if err != nil {
switch err {
case strategy.ErrNoResourcesAvailable:
var masterEngine *cluster.Engine
for _, engine := range c.engines {
for k, v := range engine.Labels {
if k == "swarmmaster" && v == "true" {
masterEngine = engine
}
}
}
containerConfig := &cluster.ContainerConfig{
dockerclient.ContainerConfig{
Image: "ankushagarwal11/machine",
Cmd: []string{"-D", "create", "--driver=amazonec2", "--amazonec2-instance-type", "t2.micro", "--amazonec2-secret-key", "INSERT_SECRET_KEY", "--amazonec2-access-key", "INSERT_ACCESS_KEY", "--amazonec2-vpc-id", "INSERT_VPC_ID", "randommachine1"},
HostConfig: dockerclient.HostConfig{
Binds: []string{"/root/.docker:/root/.docker"},
},
},
}
container, _ := masterEngine.Create(containerConfig, "random123", false)
log.Info("Created container")
masterEngine.Client.StartContainer(container.Id, &dockerclient.HostConfig{})
log.Info("Started container and now waiting")
<-masterEngine.Client.Wait(container.Id)
log.Info("Done waiting")
return nil, err
default:
return nil, err
}
}
if nn, ok := c.engines[n.ID]; ok {
container, err := nn.Create(config, name, true)
return container, err
}
return nil, nil
}