简体   繁体   English

转到“找不到提供包装的模块”

[英]“cannot find module providing for package” in go

Im trying to install the official go docker client by importing 我正在尝试通过导入来安装官方的go docker客户端

"github.com/docker/docker/client" “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 无法加载github.com/docker/distribution/reference:无法找到提供软件包github.com/docker/distribution/reference的模块

My go version is 1.12 and my project is outside $GOPATH/src. 我的go版本是1.12,我的项目在$ GOPATH / src之外。 My go.mod file looks like this. 我的go.mod文件看起来像这样。

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. 根据go get github.com/docker/docker/client 文档 ,它说您必须执行go get github.com/docker/docker/client命令来下载它。 Once library is retrieved it should compile. 一旦检索到库,就应该编译。

I remember that I had similar problems as you 1.5-2 monthes ago. 我记得我在1.5-2个月前遇到过类似的问题。

My observations : 我的观察

  • there are a lot of versions of docker API Docker API有很多版本
  • it's hard to tell which version described in "official" documentation 很难说出“官方”文档中描述的版本
  • API itself flawed API本身存在缺陷
  • source code - quite easy to understand 源代码-相当容易理解

I did not found answers for "what actually describes official documentation?" 我没有找到“实际上描述了官方文档?”的答案。 or "where actually docker API repo?" 或“码头工人API回购实际上在哪里?”

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) 使用docker / docker-ce (请注意,官方文档中的示例未经修改将不起作用)
  • instead of official documentation - just search code in docker-ce repo. 而不是官方文档-只需在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) 我在这里找到的docker docker/client使用的最佳示例: components / engine / integration / internal / container / exec.go (请注意,它位于internal ,无法用作包)
  • 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. 我认为不依赖docker文档可能对您来说更实用。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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