我很期待下面做这样的事情使用泊坞窗golang API的搬运工golang API设置集装箱港口码头工人中
CMD:搬运工运行-t -i -p 8989:8080“图像名称” /斌/庆典
而且我使用golang SDK https://github.com/moby/moby/client或https://godoc.org/github.com/moby/moby/client和我的码头工人API版本为1.30(客户&服务器两者)
下面是一段代码,我使用
package main
import (
"fmt"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"golang.org/x/net/context"
"github.com/docker/go-connections/nat"
//"github.com/docker/docker/vendor/github.com/docker/go-connections/nat"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main(){
ctx := context.Background()
cli, err := client.NewEnvClient()
check(err)
config := &container.Config{
Image : image-name,
ExposedPorts: nat.PortSet{
"8080/tcp": struct{}{},
},
Cmd : [] string {"sh","-c","while true; do sleep always; done","/bin/bash"},
}
host_config := &container.HostConfig{
PortBindings: nat.PortMap{
"8080/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: "8989",
},
},
},
}
resp, err := cli.ContainerCreate(ctx,config,host_config, nil,"")
check(err)
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{});
err != nil {
panic(err)
}
}
编译此代码后,我收到以下错误
# command-line-arguments
src\main\createcontainer1.go:53: cannot use "github.com/docker/go-connections/nat".PortSet literal (type "github.com/docker/go-connections/nat".PortSet) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value
src\main\createcontainer1.go:65: cannot use "github.com/docker/go-connections/nat".PortMap literal (type "github.com/docker/go-connections/nat".PortMap) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap in field value
如果有人知道可能是什么问题,如何解决它。 请为此回答,因为我是码头工人的初学者。
。无论如何没有它?我找不到像上面提到的供应商目录...我系统中的目录是C:\ Projects \ Go \ pkg \ windows_amd64 \ github.com \ docker \ docker \ vendor \ github.com \ docker,目录有去连接文件夹在里面。请详述。 – Insignianode
实际上,'docker'使用vendoring。你可以尝试删除'vendor'目录吗? - 错误引用它 - “不能使用”github.com/docker/go-connections/nat".PortSet文字(键入“github.com/docker/go-connections/nat".PortSet)”类型为“github.com /docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value' –
我删除了vendor目录,结果在 src \ github.com \ docker \ docker \ pkg下出错\ system \ syscall_windows.go:6:2:找不到包“github.com/Sirupsen/logrus”中的任何一个: C:\ Go \ src \ github.com \ Sirupsen \ logrus(来自$ GOROOT) C: \ Projects \ Go \ src \ github.com \ Sirupsen \ logrus(来自$ GOPATH) src \ github.com \ docker \ docker \ client \ container_commit.go:8:2:无法找到软件包“github.com/docker/分布/参考“中的任何一个: C:\ Go \ src \ github.com \ docker \ distribution \ reference(来自$ GOROOT) 和类似更像这样,请指导我解决它。 – Insignianode