docker.go 446 B

1234567891011121314151617181920212223
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/client"
  7. )
  8. func main() {
  9. cli, err := client.NewClientWithOpts(client.FromEnv)
  10. if err != nil {
  11. panic(err)
  12. }
  13. containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
  14. if err != nil {
  15. panic(err)
  16. }
  17. for _, container := range containers {
  18. fmt.Printf("%s %s\n", container.ID[:10], container.Image)
  19. }
  20. }