0

I'm new on Go.

Trying to use the docker api to manage containers.

I have been trying to create the following setup:

import (
    "github.com/docker/docker/api/types/container"
    "github.com/go-connections/nat"
)

config := &container.Config{
    Image: "nginx",
    ExposedPorts: nat.PortSet{
        "4140/tcp": struct{}{},
    },
}

unfortunately, im getting error:

Cannot use nat.PortSet{"4140/tcp": struct{}{}, }(type PortSet) as type nat.PortSet

./docker_test.go:15:15: 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

Cant understand what i'm doing wrong? Thanks!

Ofer Velich
  • 1,959
  • 4
  • 19
  • 24
  • Can you show your imports? Also, is this the actual error or redacted? If the latter, it could be similar to https://stackoverflow.com/questions/45542071/setting-ports-for-container-in-docker-for-docker-golang-api – Marc Feb 05 '18 at 09:22
  • Deleting the vendor didn't helped just like mention in the link, doesn't seems it got resolved also Added the related imports and the actual error Thanks @Marc – Ofer Velich Feb 05 '18 at 11:45
  • [this issue](https://github.com/moby/moby/issues/28269) has more details. Sorry, best I can do. – Marc Feb 05 '18 at 11:50
  • not sure whether you have solved the problem. I got into the same trouble and fixed it by deleting the vendor under $GOPATH/src/..../docker (for go mod it's another location). I hope it helps. – Musen May 09 '20 at 11:56

0 Answers0