Trouble with go module version in docker build

I am having quite an adventure trying to deploy my first application with Docker and Go Modules. This probably isn’t strictly a Go question but hopefully, someone can steer me in the right direction.

When I try to build my dockerfile I get the following errors.

go: finding github.com/gorilla/websocket v1.4.0
go: github.com/gorilla/websocket@v1.4.0: unknown revision v1.4.0
go: error loading module requirements

I’ve tried deleting my go.mod file and rebuilding it which didn’t help.

I ran go mod tidy which gave me this:
go: finding github.com/gorilla/websocket v1.4.0
go: downloading github.com/gorilla/websocket v1.4.0
go: extracting github.com/gorilla/websocket v1.4.0

But afterward, the docker build still gave the same error as before. I’m completely lost at this point.

Can you share perhaps your Dockerfile and pinpoint the location where the error occurs?

And where do you run go mod tidy? In the dockerfile? Or on your host? If the latter I’m wondering how running something on the host could affect the build in the host, unless you are copying some files over that shouldn’t be there, which would either mean your .dockerignore is not covering all the details, or even worse you are relying on a volume that holds your source code rather than using COPY/ADD.

I ended up dropping modules, which eventually led me to the solution through the back way. It turns out the error is misleading.

I tried going into the golang image itself and running go get github.com/gorilla/websocket and got the exact same error. Obviously, this meant it wasn’t an issue with modules and the revision after all. Then I remembered how much of a pain it was setting up go on my computer and the issues I had trying to “go get” anything. Then it dawned on me, I never set up docker to use the company proxy server, so it was having those same issues.

So, it wasn’t an issue with the version or my dockerfile at all. It’s just that the connection to github was blocked and the error message that docker gave was less than helpful.

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