Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created December 29, 2022 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiemonk/bb1faf361568597fd3ec251abbea6b34 to your computer and use it in GitHub Desktop.
Save veggiemonk/bb1faf361568597fd3ec251abbea6b34 to your computer and use it in GitHub Desktop.
simple docker client
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
func main() {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
panic(err)
}
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
for _, container := range containers {
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment