我试图在我自己的项目中利用docker/cli客户端库来创建/管理堆栈。
但是,我在构建项目时遇到了问题。
下面的代码:
package main
import (
"fmt"
"log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/stack"
"github.com/docker/cli/cli/flags"
)
func main() {
cli, err := command.NewDockerCli(command.WithStandardStreams())
if err != nil {
log.Fatal(err)
}
cli.Initialize(flags.NewClientOptions())
cmd := stack.NewStackCommand(cli)
cmd.SetArgs([]string{"deploy", "--compose-file", "docker-compose.yml", "test"})
err = cmd.Execute()
if err != nil {
log.Fatal(err)
}
fmt.Println("success!")
}
我已经设置了一个最小的 go.mod:
module github.com/dev/test
go 1.16
当我跑步时go get
;我收到以下错误:
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api/defaults: cannot find module providing package github.com/docker/swarmkit/api/defaults
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api/genericresource: cannot find module providing package github.com/docker/swarmkit/api/genericresource
github.com/dev/test imports
github.com/docker/cli/cli/command/stack imports
github.com/docker/cli/cli/command/service imports
github.com/docker/swarmkit/api imports
google.golang.org/grpc/transport: cannot find module providing package google.golang.org/grpc/transport
我对docker/cli repo进行了更深入的研究,似乎该项目不使用 go 模块;而是使用较旧的vendor
dir 方法。
我想知道如何让项目编译。有没有办法go get
自动引用vendor
导入docker/cli
项目目录中的包?