Docker build fails due to cannot load package

PROBLEM:
The docker build fails whenever I run "docker build . "
It says cannot load package A/B/C: module A/B@latest found (v0.0.0-20200130130556-6a5cffbc99af), but does not contain package A/B/C.

OUTPUT:

Step 1/8 : FROM golang:1.13
—> 6586e3d10e96
Step 2/8 : RUN printf “***” > ~/.netrc ## build account on bitbucket
—> Using cache
—> afccf96ed6c0
Step 3/8 : RUN mkdir -p /go/src/bitbucket.org/alishan/tapmongoservice
—> Using cache
—> af2c1ce54ce5
Step 4/8 : COPY . /go/src/bitbucket.org/alishan/tapmongoservice
—> ebec6a06817d
Step 5/8 : WORKDIR /go/src/bitbucket.org/alishan/tapmongoservice
—> Running in 0a332bb434b7
Removing intermediate container 0a332bb434b7
—> 1dcdac500f07
Step 6/8 : RUN mkdir /go/log && go build -o /go/bin
—> Running in 26e0514769e9
go: downloading bitbucket.org/alishan/tapgolib v0.0.0-20200130130556-6a5cffbc99af
go: downloading github.com/gorilla/mux v1.7.3
go: downloading github.com/gorilla/context v1.1.1
go: downloading github.com/gorilla/handlers v1.4.2
go: downloading go.mongodb.org/mongo-driver v1.2.1
go: extracting github.com/gorilla/context v1.1.1
go: extracting github.com/gorilla/handlers v1.4.2
go: extracting github.com/gorilla/mux v1.7.3
go: extracting bitbucket.org/alishan/tapgolib v0.0.0-20200130130556-6a5cffbc99af
go: extracting go.mongodb.org/mongo-driver v1.2.1
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/go-stack/stack v1.8.0
go: downloading github.com/DataDog/zstd v1.4.4
go: extracting github.com/go-stack/stack v1.8.0
go: extracting github.com/golang/snappy v0.0.1
go: extracting github.com/DataDog/zstd v1.4.4
go: finding bitbucket.org/alishan/tapgolib latest
go: finding bitbucket.org/alishan/tapgolib/mongomgr latest
go: finding github.com/gorilla/context v1.1.1
go: finding github.com/gorilla/handlers v1.4.2
go: finding github.com/gorilla/mux v1.7.3
go: finding go.mongodb.org/mongo-driver v1.2.1
go: finding github.com/go-stack/stack v1.8.0
go: finding github.com/DataDog/zstd v1.4.4
go: finding github.com/golang/snappy v0.0.1
build bitbucket.org/alishan/tapmongoservice: cannot load bitbucket.org/alishan/tapgolib/mongomgr: module bitbucket.org/alishan/tapgolib@latest found (v0.0.0-20200130130556-6a5cffbc99af), but does not contain package bitbucket.org/alishan/tapgolib/mongomgr
The command ‘/bin/sh -c mkdir /go/log && go build -o /go/bin’ returned a non-zero code: 1

Does

$ go build

work if you don’t try to build a Docker container? The module http://bitbucket.org/alishan/tapgolib/mongomgr does not exist or is not accessible.

go build works fine.
The module is not accessible because it is an organization’s private module.

Do you have a go.sum in your project when you clone it?

If not, does the package in the module actually exist on the commit that the error complaints about?

If you have a go.mod in your local project, but not in git, check if the SHA in the sum file is the same as in the error. Compare if the package has been removed since then.

To be sure, do a fresh clone outside of docker on your Dev pc and try to build it. Do not use your already existing clone. What happens there?

yes, I do have a go.sum in my project and the package is also present in the module on that commit.
SHA in the sum file is the same as in the error and the package is still present.
Outside of docker the build works fine but it again fails if built with docker,
err : build bitbucket.org/alishan/tapmongoservice: cannot load bitbucket.org/alishan/tapgolib/mongomgr: module bitbucket.org/alishan/tapgolib@latest found (v0.0.0-20200130130556-6a5cffbc99af), but does not contain package bitbucket.org/alishan/tapgolib/mongomgr

Does it work if you make the repositories public temporarily (I know this might be a potential risk for your company and I totally understand if you don’t want to try)?

Also have you checked non-docker build on a fresh clone?

I found the solution.
The imported package had repo name mongoMgr but the package name is mongomgr. I matched the package name and the repo name, now the built is successfull.

Although one new query arrises as to how do we resolve such built when package name is diff then repo name.

thanks Nobert

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.