I am trying to create a container with docker's go api. I want to expose a port using container.Config.ExposedPorts
in ContainerCreate()
API. Below is the code
package main
import (
"fmt"
"context"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
)
func main() {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.WithVersion("1.38"))
if err != nil {
fmt.Println("Failed to get container envoronment", err)
}
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: "hyperledger/fabric-ca",
Cmd: []string{"/bin/sh", "-c", "fabric-ca-server start -b admin:adminpw"},
Env: []string{"FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server",
"FABRIC_CA_SERVER_CA_NAME=ca.example.com"},
ExposedPorts: nat.PortSet{"22/tcp":struct{}{},},
}, nil, nil, "ca.example.com")
if err != nil {
fmt.Println(" failed to create container, err:", err)
} else {
fmt.Println(" Container ID :", resp.ID, "warning:", resp.Warnings, "err:", err)
}
}
when I compile I get the below error
vignesh@vignesh-ThinkPad-E470 ~/go-book/src/github.com/my_fabric $ go build asd.go
asd.go:8:9: cannot find package "github.com/docker/go-connections/nat" in any of:
/home/vignesh/go-book/src/github.com/my_fabric/vendor/github.com/docker/go-connections/nat (vendor tree)
/usr/local/go/src/github.com/docker/go-connections/nat (from $GOROOT)
/home/vignesh/go-book/src/github.com/docker/go-connections/nat (from $GOPATH)
As package "github.com/docker/go-connections/nat"
is in a vendor directory at "github.com/docker/docker/vendor/github.com/docker/go-connections/nat"
, I then created a vendor directory in my working directory and copied contents of github.com/docker/docker/vendor/github.com/docker/go-connections/nat
to github.com/my_fabric/vendor/go-connections/nat
and used "github.com/my_fabric/go-connections/nat"
in import rather than "github.com/docker/go-connections/nat"
. But I got the following error.
vignesh@vignesh-ThinkPad-E470 ~/go-book/src/github.com/my_fabric $ go build asd.go
# command-line-arguments
./asd.go:25:29: cannot use "github.com/my_fabric/vendor/github.com/my_fabric/go-connections/nat".PortSet literal (type "github.com/my_fabric/vendor/github.com/my_fabric/go-connections/nat".PortSet) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value
Basically I want to use packages which is in vendor directory in docker's repository. Kindly help :)