本文整理匯總了Golang中github.com/docker/swarm/cluster.ContainerConfig.SetSwarmID方法的典型用法代碼示例。如果您正苦於以下問題:Golang ContainerConfig.SetSwarmID方法的具體用法?Golang ContainerConfig.SetSwarmID怎麽用?Golang ContainerConfig.SetSwarmID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarm/cluster.ContainerConfig
的用法示例。
在下文中一共展示了ContainerConfig.SetSwarmID方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createContainer
func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string, withImageAffinity bool, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) {
c.scheduler.Lock()
// Ensure the name is available
if !c.checkNameUniqueness(name) {
c.scheduler.Unlock()
return nil, fmt.Errorf("Conflict: The name %s is already assigned. You have to delete (or rename) that container to be able to assign %s to a container again.", name, name)
}
swarmID := config.SwarmID()
if swarmID == "" {
// Associate a Swarm ID to the container we are creating.
swarmID = c.generateUniqueID()
config.SetSwarmID(swarmID)
}
if network := c.Networks().Get(config.HostConfig.NetworkMode); network != nil && network.Scope == "local" {
if !config.HaveNodeConstraint() {
config.AddConstraint("node==~" + network.Engine.Name)
}
config.HostConfig.NetworkMode = network.Name
}
if withImageAffinity {
config.AddAffinity("image==" + config.Image)
}
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
if withImageAffinity {
config.RemoveAffinity("image==" + config.Image)
}
if err != nil {
c.scheduler.Unlock()
return nil, err
}
n := nodes[0]
engine, ok := c.engines[n.ID]
if !ok {
c.scheduler.Unlock()
return nil, fmt.Errorf("error creating container")
}
c.pendingContainers[swarmID] = &pendingContainer{
Name: name,
Config: config,
Engine: engine,
}
c.scheduler.Unlock()
container, err := engine.Create(config, name, true, authConfig)
c.scheduler.Lock()
delete(c.pendingContainers, swarmID)
c.scheduler.Unlock()
return container, err
}
示例2: 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 {
return nil, err
}
if nn, ok := c.engines[n.ID]; ok {
container, err := nn.Create(config, name, true)
return container, err
}
return nil, nil
}
示例3: CreateContainer
// CreateContainer aka schedule a brand new container into the cluster.
func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string) (*cluster.Container, error) {
c.scheduler.Lock()
defer c.scheduler.Unlock()
// Ensure the name is avaliable
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())
n, err := c.scheduler.SelectNodeForContainer(c.listNodes(), config)
if err != nil {
return nil, err
}
if nn, ok := c.engines[n.ID]; ok {
container, err := nn.Create(config, name, true)
if err != nil {
return nil, err
}
st := &state.RequestedState{
ID: container.Id,
Name: name,
Config: config,
}
return container, c.store.Add(container.Id, st)
}
return nil, nil
}
示例4: 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
}
示例5: createContainer
func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string, withSoftImageAffinity bool, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) {
c.scheduler.Lock()
// Ensure the name is available
if !c.checkNameUniqueness(name) {
c.scheduler.Unlock()
return nil, fmt.Errorf("Conflict: The name %s is already assigned. You have to delete (or rename) that container to be able to assign %s to a container again.", name, name)
}
// Associate a Swarm ID to the container we are creating.
swarmID := c.generateUniqueID()
config.SetSwarmID(swarmID)
configTemp := config
if withSoftImageAffinity {
configTemp.AddAffinity("image==~" + config.Image)
}
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), configTemp)
if err != nil {
c.scheduler.Unlock()
return nil, err
}
n := nodes[0]
engine, ok := c.engines[n.ID]
if !ok {
c.scheduler.Unlock()
return nil, fmt.Errorf("error creating container")
}
c.pendingContainers[swarmID] = &pendingContainer{
Name: name,
Config: config,
Engine: engine,
}
c.scheduler.Unlock()
container, err := engine.Create(config, name, true, authConfig)
c.scheduler.Lock()
delete(c.pendingContainers, swarmID)
c.scheduler.Unlock()
return container, err
}