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
)

上一篇:强大的滤镜配置软件


下一篇:Excel19定义名称&&INDIRECT - 7 images