本文整理匯總了Golang中github.com/openshift/geard/docker.DockerClient.InspectContainer方法的典型用法代碼示例。如果您正苦於以下問題:Golang DockerClient.InspectContainer方法的具體用法?Golang DockerClient.InspectContainer怎麽用?Golang DockerClient.InspectContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/geard/docker.DockerClient
的用法示例。
在下文中一共展示了DockerClient.InspectContainer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RunCommandInContainer
func RunCommandInContainer(client *docker.DockerClient, name string, command []string, environment []string) (int, error) {
if len(command) == 0 {
fmt.Println("No command specified")
os.Exit(3)
}
container, err := client.InspectContainer(name)
if err != nil {
fmt.Printf("Unable to locate container named %v\n", name)
os.Exit(3)
}
containerNsPID, err := client.ChildProcessForContainer(container)
if err != nil {
fmt.Println("Couldn't create child process for container")
os.Exit(3)
}
containerEnv := environment
if len(containerEnv) == 0 {
containerEnv = container.Config.Env
}
return RunIn(name, containerNsPID, command, containerEnv)
}
示例2: isContainerAvailable
func isContainerAvailable(client *docker.DockerClient, id string) (bool, error) {
container, err := client.InspectContainer(id)
if err == docker.ErrNoSuchContainer {
return false, nil
}
if err != nil {
return true, err
}
if container.State.Running && container.State.Pid != 0 {
return true, nil
}
return false, nil
}
示例3: InitPostStart
func InitPostStart(dockerSocket string, id containers.Identifier) error {
var (
u *user.User
container *dc.Container
err error
d *docker.DockerClient
)
if u, err = user.Lookup(id.LoginFor()); err == nil {
if err := ssh.GenerateAuthorizedKeysFor(u, true, false); err != nil {
log.Print(err.Error())
}
} else {
log.Print(err.Error())
}
if d, err = docker.GetConnection(dockerSocket); err != nil {
return err
}
if file, err := os.Open(id.NetworkLinksPathFor()); err == nil {
defer file.Close()
const ContainerInterval = time.Second / 10
const ContainerWait = time.Second * 15
for i := 0; i < int(ContainerWait/ContainerInterval); i++ {
if container, err = d.InspectContainer(id.ContainerFor()); err != nil {
if err == docker.ErrNoSuchContainer {
//log.Printf("Waiting for container to be available.")
time.Sleep(ContainerInterval)
continue
}
return err
}
if container.State.Running && container.State.Pid != 0 {
break
} else {
//log.Printf("Waiting for container to report available.")
time.Sleep(ContainerInterval)
}
}
if container == nil {
return fmt.Errorf("container %s was not visible through Docker before timeout", id.ContainerFor())
}
pid, err := d.ChildProcessForContainer(container)
if err != nil {
return err
}
if pid <= 1 {
return errors.New("child PID is not correct")
}
log.Printf("Updating network namespaces for %d", pid)
if err := updateNamespaceNetworkLinks(pid, file); err != nil {
return err
}
}
return nil
}