本文整理汇总了Golang中github.com/samalba/dockerclient.DockerClient类的典型用法代码示例。如果您正苦于以下问题:Golang DockerClient类的具体用法?Golang DockerClient怎么用?Golang DockerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DockerClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deleteImage
func deleteImage(docker *dockerclient.DockerClient, imageIDs []string) []error {
var errors []error
if !noConfirm {
var answer string
fmt.Printf("This will delete %v images\n", len(imageIDs))
fmt.Printf("Do you want to continue? (yes/no)\n")
fmt.Scanln(&answer)
if answer != "yes" {
fmt.Printf("%v", answer)
return nil
}
}
for _, imageID := range imageIDs {
imageDelete, deleteErr := docker.RemoveImage(imageID)
if deleteErr != nil {
errors = append(errors, deleteErr)
}
for _, id := range imageDelete {
if id.Deleted != "" {
log.Printf("DELETED: %v", id.Deleted)
}
if id.Untagged != "" {
log.Printf("UNTAGGED: %#v", id.Untagged)
}
}
}
if len(errors) > 0 {
return errors
}
return nil
}
开发者ID:kadel,项目名称:dockercleaner,代码行数:32,代码来源:dockercleaner.go
示例2: GetContainers
func (n *Node) GetContainers(do *dockerclient.DockerClient) ([]dockerclient.Container, error) {
containers, err := do.ListContainers(false, false, "")
if err != nil {
log.Fatal(err)
}
return containers, err
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:7,代码来源:NodeInfo.go
示例3: GetImages
func (n *Node) GetImages(do *dockerclient.DockerClient) ([]*dockerclient.Image, error) {
images, err := do.ListImages(false)
if err != nil {
log.Fatal(err)
}
return images, err
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:7,代码来源:NodeInfo.go
示例4: ListImagesDetailed
func ListImagesDetailed(dockerClient *dockerclient.DockerClient, all bool) ([]*DetailedImageInfo, error) {
images, err := dockerClient.ListImages(all)
if err != nil {
return nil, err
}
var result = make([]*DetailedImageInfo, len(images))
for i, image := range images {
imagesDetails, _ := InspectImage(dockerClient, image.Id)
detailedImageInfo := DetailedImageInfo{
Created: image.Created,
Id: image.Id,
ParentId: image.ParentId,
RepoTags: image.RepoTags,
Size: image.Size,
VirtualSize: image.VirtualSize,
Architecture: imagesDetails.Architecture,
Author: imagesDetails.Author,
Comment: imagesDetails.Comment,
Container: imagesDetails.Container,
DockerVersion: imagesDetails.Container,
Os: imagesDetails.Os}
result[i] = &detailedImageInfo
}
return result, nil
}
开发者ID:th3architect,项目名称:sherdock,代码行数:25,代码来源:images.go
示例5: stopCotainers
func stopCotainers(docker *dockerclient.DockerClient, imageIDs []string) []error {
var errors []error
if !noConfirm {
var answer string
fmt.Printf("This will stop %v images\n", len(imageIDs))
fmt.Printf("Do you want to continue? (yes/no)\n")
fmt.Scanln(&answer)
if answer != "yes" {
fmt.Printf("%v", answer)
return nil
}
}
for _, imageID := range imageIDs {
stopErr := docker.StopContainer(imageID, 10)
if stopErr != nil {
errors = append(errors, stopErr)
} else {
log.Printf("STOPPED: %v", imageID)
}
}
if len(errors) > 0 {
return errors
}
return nil
}
开发者ID:kadel,项目名称:dockercleaner,代码行数:26,代码来源:dockercleaner.go
示例6: 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
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:9,代码来源:NodeInfo.go
示例7: stopAndDeleteDevice
func stopAndDeleteDevice(deviceSn string, docker *dc.DockerClient) error {
container := "device" + deviceSn
err := docker.KillContainer(container)
if err != nil {
return err
}
err = docker.RemoveContainer(container)
return nil
}
开发者ID:jvermillard,项目名称:daas,代码行数:10,代码来源:main.go
示例8: removeImages
func removeImages(client *dockerclient.DockerClient, images []*dockerclient.Image) error {
for _, image := range images {
log.Print("rmi ", image.Id)
if !*dry {
if _, err := client.RemoveImage(image.Id); err != nil {
debug("Couldn't remove image: %s", err)
}
}
}
return nil
}
开发者ID:dawidmalina,项目名称:docker-proper,代码行数:11,代码来源:docker-proper.go
示例9: GetInjectorsForPolicy
func GetInjectorsForPolicy(client *docker.DockerClient, name string) ([]injector, error) {
is := []injector{}
cs, err := client.ListContainers(true, false, fmt.Sprintf(`{"label":["%s=%s"]}`, AGENT_LABEL, name))
if err != nil {
return is, err
}
for _, c := range cs {
is = append(is, InjectorFromContainer(c))
}
return is, nil
}
开发者ID:ZhukovAlexander,项目名称:entropy,代码行数:11,代码来源:policy.go
示例10: removeContainers
func removeContainers(client *dockerclient.DockerClient, containers []*dockerclient.ContainerInfo) error {
for _, container := range containers {
log.Printf("rm %s (%s)", container.Id, container.Name)
if !*dry {
if err := client.RemoveContainer(container.Id, false, false); err != nil {
debug("Couldn't remove container: %s", err)
}
}
}
return nil
}
开发者ID:dawidmalina,项目名称:docker-proper,代码行数:11,代码来源:docker-proper.go
示例11: 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
}
开发者ID:th3architect,项目名称:sherdock,代码行数:15,代码来源:containers.go
示例12: list_containers
func list_containers(docker *dockerclient.DockerClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Get only running containers
containers, err := docker.ListContainers(false, false, "")
if err != nil {
log.Fatal(err)
}
dat, err := json.MarshalIndent(&containers, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, string(dat))
}
}
开发者ID:odewahn,项目名称:thebe-server,代码行数:16,代码来源:list.go
示例13: startContainer
func startContainer(docker *dockerclient.DockerClient, containerId string, additionalCapabilities []string, ctx *ContainerContext) error {
//Build the port bindings needed when running the container
dockerHostConfig := new(dockerclient.HostConfig)
dockerHostConfig.PortBindings = make(map[string][]dockerclient.PortBinding)
for k, v := range ctx.PortContext {
pb := dockerclient.PortBinding{HostPort: v}
portBindings := []dockerclient.PortBinding{pb}
dockerHostConfig.PortBindings[k] = portBindings
}
dockerHostConfig.Links = ctx.Links
dockerHostConfig.CapAdd = additionalCapabilities
//Start the container
return docker.StartContainer(containerId, dockerHostConfig)
}
开发者ID:xtraclabs,项目名称:roll,代码行数:16,代码来源:docker_support.go
示例14: requiredImageAvailable
func requiredImageAvailable(docker *dockerclient.DockerClient, name string) bool {
images, err := docker.ListImages(true)
if err != nil {
log.Fatal(err)
}
for _, i := range images {
for _, t := range i.RepoTags {
if strings.Index(t, name) == 0 {
return true
}
}
}
return false
}
开发者ID:xtraclabs,项目名称:roll,代码行数:16,代码来源:docker_support.go
示例15: InspectImage
func InspectImage(dockerClient *dockerclient.DockerClient, id string) (*dockerclient.ImageInfo, error) {
cachedImageInfo, _ := imageCache.Get(id)
if cachedImageInfo == nil {
imageInfo, err := dockerClient.InspectImage(id)
if err != nil {
return nil, err
}
imageCache.Add(id, imageInfo)
return imageInfo, nil
} else {
if cachedImageInfoCasted, ok := cachedImageInfo.(*dockerclient.ImageInfo); ok {
return cachedImageInfoCasted, nil
} else {
return nil, fmt.Errorf("Cache casting error")
}
}
}
开发者ID:th3architect,项目名称:sherdock,代码行数:17,代码来源:images.go
示例16: Exec
func (job *Job) Exec(docker *dockerclient.DockerClient,
w io.Writer) error {
containerConfig := &dockerclient.ContainerConfig{
Image: job.Image,
Cmd: []string{"/bin/bash", "-c", job.Cmd},
AttachStdout: true,
AttachStderr: true,
}
cid, err := docker.CreateContainer(containerConfig,
fmt.Sprintf("spot-trader-job-%d", job.ID))
if err != nil {
return fmt.Errorf("creating container: %v", err)
}
defer func() {
if err = docker.RemoveContainer(cid, false, false); err != nil {
log.Printf("error removing container: %v", err)
}
}()
options := &dockerclient.AttachOptions{Stdout: true, Stderr: true, Stream: true}
stdout, err := docker.AttachContainer(cid, options)
if err != nil {
return fmt.Errorf("attaching: %v", err)
}
err = docker.StartContainer(cid, nil)
if err != nil {
return fmt.Errorf("starting container: %v", err)
}
done := make(chan struct{})
go func() {
err := copyDockerOut(w, w, stdout)
if err != nil {
log.Println(err)
}
stdout.Close()
close(done)
}()
<-done
err = docker.StopContainer(cid, 5)
if err != nil {
log.Printf("error stopping container: %v",
err)
}
return nil
}
开发者ID:bajh,项目名称:spot-trader,代码行数:45,代码来源:worker.go
示例17: listDevices
func listDevices(docker *dc.DockerClient) []string {
containers, err := docker.ListContainers(false)
if err != nil {
panic(err)
}
res := make([]string, 0, 10)
for _, c := range containers {
name := arrayToStr(c.Names)
if strings.HasPrefix(name, "/device") {
// found a device container
res = append(res, name[len("/device"):])
}
}
return res
}
开发者ID:jvermillard,项目名称:daas,代码行数:18,代码来源:main.go
示例18: 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
}
开发者ID:th3architect,项目名称:sherdock,代码行数:54,代码来源:gc.go
示例19: loadImages
func loadImages(client *dockerclient.DockerClient, db *sql.DB) error {
images, err := client.ListImages()
if err != nil {
return err
}
if _, err := db.Exec(
"CREATE TABLE images (id, parent_id, size, virtual_size, tag, created)"); err != nil {
return err
}
for _, i := range images {
created := time.Unix(i.Created, 0)
if _, err := db.Exec(
"INSERT INTO images (id, parent_id, size, virtual_size, tag, created) VALUES (?, ?, ?, ?, ?, ?)",
i.Id, i.ParentId, i.Size, i.VirtualSize, i.RepoTags[0], created); err != nil {
return err
}
}
return nil
}
开发者ID:ikeee,项目名称:dockersql,代码行数:19,代码来源:images.go
示例20: supprDocker
func supprDocker(docker *dockerclient.DockerClient, dockerName string) {
var searchDockerName string = "{\"name\":[\"" + dockerName + "\"]}"
//l4g.Info("%v\n", searchDockerName)
// Get only running containers
containers, err := docker.ListContainers(true, true, searchDockerName)
if err != nil {
log.Fatal(err)
}
for _, c := range containers {
l4g.Info(c.Id, c.Names)
if err := docker.RemoveContainer(c.Id, true, false); err != nil {
//l4g.Info("cannot stop container: %s", err)
var RS string = fmt.Sprintf("cannot stop container: %s", err)
l4g.Info(RS)
writeSDLstr(RS)
}
}
}
开发者ID:AlexandreBRUXELLE,项目名称:goStartDockerViaRabbitMQ,代码行数:21,代码来源:main.go
注:本文中的github.com/samalba/dockerclient.DockerClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论