本文整理汇总了Golang中github.com/control-center/serviced/domain/servicestate.ServiceState.DockerID方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceState.DockerID方法的具体用法?Golang ServiceState.DockerID怎么用?Golang ServiceState.DockerID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/control-center/serviced/domain/servicestate.ServiceState
的用法示例。
在下文中一共展示了ServiceState.DockerID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateInstance
func updateInstance(state *servicestate.ServiceState, ctr *docker.Container) error {
if _, err := ctr.Inspect(); err != nil {
return err
}
state.DockerID = ctr.ID
state.Started = ctr.Created
state.PrivateIP = ctr.NetworkSettings.IPAddress
state.PortMapping = make(map[string][]domain.HostIPAndPort)
for k, v := range ctr.NetworkSettings.Ports {
pm := []domain.HostIPAndPort{}
for _, pb := range v {
pm = append(pm, domain.HostIPAndPort{HostIP: pb.HostIp, HostPort: pb.HostPort})
state.PortMapping[string(k)] = pm
}
}
return nil
}
示例2: AttachService
// AttachService attempts to attach to a running container
func (a *HostAgent) AttachService(svc *service.Service, state *servicestate.ServiceState, exited func(string)) error {
ctr, err := docker.FindContainer(state.DockerID)
if err != nil {
return err
}
if !ctr.IsRunning() {
defer exited(state.ID)
return nil
}
ctr.OnEvent(docker.Die, func(cid string) {
defer exited(state.ID)
glog.Infof("Instance %s (%s) for %s (%s) has died", state.ID, ctr.ID, svc.Name, svc.ID)
state.DockerID = cid
a.removeInstance(state.ID, ctr)
})
go a.setProxy(svc, ctr)
return nil
}
示例3: StartService
// StartService starts a new instance of the specified service and updates the control center state accordingly.
func (a *HostAgent) StartService(svc *service.Service, state *servicestate.ServiceState, exited func(string)) error {
glog.V(2).Infof("About to start service %s with name %s", svc.ID, svc.Name)
client, err := NewControlClient(a.master)
if err != nil {
glog.Errorf("Could not start ControlPlane client %v", err)
return err
}
defer client.Close()
// start from a known good state
if state.DockerID != "" {
if ctr, err := docker.FindContainer(state.DockerID); err != nil {
glog.Errorf("Could not find container %s for %s", state.DockerID, state.ID)
} else if err := ctr.Delete(true); err != nil {
glog.Errorf("Could not delete container %s for %s", state.DockerID, state.ID)
}
}
// create the docker client Config and HostConfig structures necessary to create and start the service
config, hostconfig, err := configureContainer(a, client, svc, state, a.virtualAddressSubnet)
if err != nil {
glog.Errorf("can't configure container: %v", err)
return err
}
cjson, _ := json.MarshalIndent(config, "", " ")
glog.V(3).Infof(">>> CreateContainerOptions:\n%s", string(cjson))
hcjson, _ := json.MarshalIndent(hostconfig, "", " ")
glog.V(3).Infof(">>> HostConfigOptions:\n%s", string(hcjson))
cd := &docker.ContainerDefinition{
dockerclient.CreateContainerOptions{Name: state.ID, Config: config},
*hostconfig,
}
ctr, err := docker.NewContainer(cd, false, 10*time.Second, nil, nil)
if err != nil {
glog.Errorf("Error trying to create container %v: %v", config, err)
return err
}
var started sync.WaitGroup
started.Add(1)
ctr.OnEvent(docker.Start, func(cid string) {
glog.Infof("Instance %s (%s) for %s (%s) has started", state.ID, ctr.ID, svc.Name, svc.ID)
started.Done()
})
ctr.OnEvent(docker.Die, func(cid string) {
defer exited(state.ID)
glog.Infof("Instance %s (%s) for %s (%s) has died", state.ID, ctr.ID, svc.Name, svc.ID)
state.DockerID = cid
a.removeInstance(state.ID, ctr)
})
if err := ctr.Start(time.Hour); err != nil {
glog.Errorf("Could not start service state %s (%s) for service %s (%s): %s", state.ID, ctr.ID, svc.Name, svc.ID, err)
a.removeInstance(state.ID, ctr)
return err
}
started.Wait()
if err := updateInstance(state, ctr); err != nil {
glog.Errorf("Could not update instance %s (%s) for service %s (%s): %s", state.ID, ctr.ID, svc.Name, svc.ID, err)
ctr.Stop(45 * time.Second)
return err
}
go a.setProxy(svc, ctr)
return nil
}