connect_dockerd_without_tls
作者:互联网
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
func main() {
// ctx := context.Background()
cli, err := client.NewClientWithOpts(client.WithHost("tcp://192.168.160.101:2375"),client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
for _, container := range containers {
fmt.Println(container.ID)
}
}
cat go.mod
module test-docker
go 1.16
require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/containerd/containerd v1.5.1 // indirect
github.com/docker/docker v20.10.6+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
google.golang.org/grpc v1.37.1 // indirect
)
标签:tls,github,err,without,connect,go,indirect,com,docker 来源: https://blog.csdn.net/qq_21442867/article/details/117297141