简体   繁体   中英

“cannot find module providing for package” in go

Im trying to install the official go docker client by importing

"github.com/docker/docker/client"

But i get the following error

cannot load github.com/docker/distribution/reference: cannot find module providing package github.com/docker/distribution/reference

My go version is 1.12 and my project is outside $GOPATH/src. My go.mod file looks like this.

module app

go 1.12

require (
  github.com/Microsoft/go-winio v0.4.14 // indirect
  github.com/docker/docker v1.13.1
  github.com/docker/go-connections v0.4.0 // indirect
  github.com/docker/go-units v0.4.0 // indirect
  golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
)

Based on docker documentation , it says that you have to execute go get github.com/docker/docker/client command to download it. Once library is retrieved it should compile.

I remember that I had similar problems as you 1.5-2 monthes ago.

My observations :

  • there are a lot of versions of docker API
  • it's hard to tell which version described in "official" documentation
  • API itself flawed
  • source code - quite easy to understand

I did not found answers for "what actually describes official documentation?" or "where actually docker API repo?"

I gave up on attempts to solve in "official way" and found that more practical to use "unofficial"

"Unofficial way" :

  • use docker/docker-ce (note that examples from official documentation will not work without modification)
  • instead of official documentation - just search code in docker-ce repo.
  • best example of docker/client usage I found here: components/engine/integration/internal/container/exec.go (note that it resides in internal and is impossible to be used as package)
  • I grabbed code that I needed into my package and solved the problem I had

Maybe it's "incorrect" solution but it worked for me.

I suppose it could be more practical for you to not rely on docker documentation too.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM