Official client semi broken
eyJhb opened this issue · 4 comments
Just wanted to point up, that the most basic of features are broken in the official client, and should be noted.. Hence the reason for sticking with this library, see here - moby/moby#28269
Even this simple port code won't work.
package main
import (
"context"
"log"
"github.com/docker/docker/api/types"
docker "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
)
func main() {
ctx := context.TODO()
// init stuff
cli, err := docker.NewClientWithOpts()
if err != nil {
log.Fatal(err)
}
cli.NegotiateAPIVersion(ctx)
// make container config
var conf types.ContainerCreateConfig
_, portBindings, err := nat.ParsePortSpecs([]string{"8080:8080/tcp"})
if err != nil {
log.Fatal(err)
}
portmap := nat.PortMap(portBindings)
conf.HostConfig.PortBindings = portmap
}
Maybe this should be noted?
Yikes I wasn't aware of that issue. On a plus side, once docker/docker migrates to go modules, this issue should be resolved. Until then, users will need to continue stripping the vendor directory, as docker mixes the main package & library packages in the same repo.
@eyJhb thanks for pointing that out. I'll amend the note in the README to mention potential shortcomings with the official SDK and vendoring.
Hoping it will happen, but I just see no mention for it. And the issue is pretty dated...
But thanks for the quick response @fsouza ! Really appreciate it, and great work on this client for go ;) Will continue to use it, seeing as it works better than the official.