您好,欢迎访问代理记账网站
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

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
)


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进