本文整理汇总了Golang中github.com/samalba/dockerclient.DockerClient.InspectContainer方法的典型用法代码示例。如果您正苦于以下问题:Golang DockerClient.InspectContainer方法的具体用法?Golang DockerClient.InspectContainer怎么用?Golang DockerClient.InspectContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/samalba/dockerclient.DockerClient
的用法示例。
在下文中一共展示了DockerClient.InspectContainer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InspectContainer
func (n *Node) InspectContainer(do *dockerclient.DockerClient, id string) (*dockerclient.ContainerInfo, error) {
containerInfo := &dockerclient.ContainerInfo{}
var err error
containerInfo, err = do.InspectContainer(id)
if err != nil {
log.Fatal(err)
}
return containerInfo, err
}
示例2: runGC
func runGC(dockerClient *dockerclient.DockerClient, filters ...string) (bool, error) {
done := true
images, err := dockerClient.ListImages(true)
if err != nil {
return true, err
}
imagesToSave := make(map[string]bool)
for _, image := range images {
for _, repoTag := range image.RepoTags {
for _, regexFilter := range filters {
if match, _ := regexp.MatchString(regexFilter, repoTag); match {
log.Printf("Image %v matches regexp /%s/ to keep\n", image.Id, regexFilter)
imagesToSave[image.Id] = true
}
}
}
}
for _, i := range images {
if i.ParentId != "" {
log.Printf("Image %s has children\n", i.ParentId)
imagesToSave[i.ParentId] = true
}
}
containers, err := dockerClient.ListContainers(true, false, "")
if err != nil {
return true, err
}
for _, c := range containers {
info, _ := dockerClient.InspectContainer(c.Id)
log.Printf("Image %s in use by container %v\n", info.Image, c.Id)
imagesToSave[info.Image] = true
}
for _, image := range images {
if !imagesToSave[image.Id] {
log.Printf("Deleting image with image id %s %v\n", image.Id, image.RepoTags)
done = false
_, err = dockerClient.RemoveImage(image.Id)
if err != nil {
log.Println("Failed to delete image: ", err)
}
}
}
log.Println("Done with images GC")
return done, nil
}
示例3: ListContainersDetailed
func ListContainersDetailed(dockerClient *dockerclient.DockerClient) ([]*dockerclient.ContainerInfo, error) {
containers, err := dockerClient.ListContainers(true, false, "")
if err != nil {
return nil, err
}
var result = make([]*dockerclient.ContainerInfo, len(containers))
for i, container := range containers {
containerInfo, err := dockerClient.InspectContainer(container.Id)
if err != nil {
return nil, err
}
result[i] = containerInfo
}
return result, nil
}
示例4: GetAcceptanceTestContainerInfo
func GetAcceptanceTestContainerInfo(docker *dockerclient.DockerClient, containerType string) *dockerclient.ContainerInfo {
// Get only running containers
containers, err := docker.ListContainers(false, false, "")
if err != nil {
log.Fatal(err)
}
//Loop through them until we find a match
for _, c := range containers {
xtContainerType, ok := c.Labels["xt-container-type"]
if ok && xtContainerType == containerType {
//Grab the information for the container
info, err := docker.InspectContainer(c.Id)
if err != nil {
log.Fatal(err)
}
return info
}
}
return nil
}
示例5: getExpired
func getExpired(client *dockerclient.DockerClient) (expiredContainers []*dockerclient.ContainerInfo, expiredImages []*dockerclient.Image, err error) {
now := time.Now()
// Containers
containers, err := client.ListContainers(true, false, "") // true = all containers
if err != nil {
return nil, nil, err
}
usedVolumeContainers := map[string]int{}
usedImages := map[string]int{}
oldContainers := []*dockerclient.ContainerInfo{}
for _, c := range containers {
debug("< container: %s", c.Id)
container, err := client.InspectContainer(c.Id)
if err != nil {
debug(" + Couldn't inspect container %s, skipping: %s", c.Id, err)
continue
}
// Increment reference counter refering to how many containers use volume container and image
if len(container.HostConfig.VolumesFrom) > 0 {
for _, vc := range container.HostConfig.VolumesFrom {
usedVolumeContainers[vc]++
}
}
debug(" + Container %s uses image %s", c.Id, container.Image)
usedImages[container.Image]++
if container.State.Running {
debug(" + Container is still running")
continue
}
debug(" + not running")
if container.State.FinishedAt == time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC) && !*unsafe {
debug(" + Container %s has empty FinishedAt field, skipping", c.Id)
continue
}
created, err := time.Parse(time.RFC3339, container.Created)
if err != nil {
return nil, nil, err
}
debug(" + Container and image threshold %s", now.Add(-*ageContainer))
if created.After(now.Add(-*ageContainer)) {
debug(" + Creation time is not old enough: %s", created)
continue
}
debug(" + Creation time is older than %s", *ageContainer)
if container.State.FinishedAt.After(now.Add(-*ageContainer)) {
debug(" + Exit time is not old enough: %s", container.State.FinishedAt)
continue
}
debug(" + Exit time is older than %s", *ageContainer)
// Decrement reference counter for old containers
if len(container.HostConfig.VolumesFrom) > 0 {
for _, vc := range container.HostConfig.VolumesFrom {
usedVolumeContainers[vc]--
}
}
usedImages[container.Image]--
oldContainers = append(oldContainers, container)
}
for _, c := range oldContainers {
name := c.Name[1:] // Remove leading /
if usedVolumeContainers[name] > 0 {
continue
}
expiredContainers = append(expiredContainers, c)
}
log.Printf("Found %d expired containers", len(expiredContainers))
// Images
images, err := client.ListImages(true)
if err != nil {
return nil, nil, err
}
for _, image := range images {
debug("< image id: %s", image.Id)
ctime := time.Unix(image.Created, 0)
if ctime.After(now.Add(-*ageImage)) {
continue
}
debug(" + older than %s", *ageImage)
if usedImages[image.Id] > 0 {
debug(" + in use, skipping")
continue
}
expiredImages = append(expiredImages, image)
}
log.Printf("Found %d expired images", len(expiredImages))
return expiredContainers, expiredImages, nil
}
示例6: createTupperware
func createTupperware(i int, uri *url.URL, docker *dockerclient.DockerClient) {
defer wg.Done()
logrus.Infof("Giving tupperware container %d some spears", i)
// create the command flags to pass to ab
cmd := []string{
"ab",
"-c",
strconv.Itoa(concurrency),
"-n",
strconv.Itoa(requests),
"-m",
strings.ToUpper(method),
"-s",
strconv.Itoa(timeout),
"-v",
strconv.Itoa(verbosity),
"-f",
protocol,
}
if authHeader != "" {
cmd = append(cmd, []string{"-A", authHeader}...)
}
if proxyAuth != "" {
cmd = append(cmd, []string{"-P", proxyAuth}...)
}
if contentType != "" {
cmd = append(cmd, []string{"-T", contentType}...)
}
if timelimit > 0 {
cmd = append(cmd, []string{"-t", strconv.Itoa(timelimit)}...)
}
if len(headers) > 0 {
for _, header := range headers {
cmd = append(cmd, []string{"-H", header}...)
}
}
if len(cookies) > 0 {
for _, cookie := range cookies {
cmd = append(cmd, []string{"-C", cookie}...)
}
}
// append the uri to the cmd string
// make sure there is a trailing slash if none given
if uri.Path == "" {
uri.Path = "/"
}
cmd = append(cmd, uri.String())
// create the container
containerConfig := &dockerclient.ContainerConfig{
Image: "jess/ab",
Entrypoint: []string{"top"},
}
name := fmt.Sprintf("tws_%d", i)
id, err := docker.CreateContainer(containerConfig, name)
if err != nil {
logrus.Errorf("Error while creating container (%s): %v", name, err)
return
}
containers = append(containers, id)
// start the container
hostConfig := &dockerclient.HostConfig{}
if err = docker.StartContainer(id, hostConfig); err != nil {
logrus.Errorf("Error while starting container (%s): %v", name, err)
return
}
// we have to start the container _before_ adding the new default gateway
// for outbound traffic, its unfortunate but yeah we need the pid of the process
if cidr != "" {
// get the pid of the container
info, err := docker.InspectContainer(id)
if err != nil {
logrus.Errorf("Error while inspecting container (%s): %v", name, err)
return
}
pid := info.State.Pid
nsPidPath := path.Join(netnsPath, strconv.Itoa(pid))
// defer removal of the pid from /var/run/netns
defer os.RemoveAll(nsPidPath)
// create a symlink from proc to the netns pid
procPidPath := path.Join("/proc", strconv.Itoa(pid), "ns", "net")
if err := os.Symlink(procPidPath, nsPidPath); err != nil {
logrus.Errorf("could not create symlink from %s to %s: %v", procPidPath, nsPidPath, err)
}
// create the veth pair and add to bridge
local, guest, err := ovs.CreateVethPair(bridge)
if err != nil {
logrus.Error(err)
return
}
//.........这里部分代码省略.........