Where to copy vendor to the go docker builder?

1,056 views
Skip to first unread message

K Prayogo

unread,
Sep 1, 2021, 9:54:54 PM9/1/21
to golang-nuts
I'm trying to make docker build faster for software that are built with golang
tried to cache layer but it still slow when dependency changed since go mod download have to redownload whole dependency again and again.

how to make use vendor directory on docker  build? (where to copy? so go build or go mod download/go mod vendor inside Dockerfile so it doesn't redownload agian and again)?
I've tried to copy whole vendor, but it still redownloading
tried to copy vendor to $GOPATH/pkg/mod, but it also still redownloading
tried to copy vendor to $GOPATH/pkg/mod/cache/download, but it still redownloading
where the correct way to put vendor directory?

Sean Liao

unread,
Sep 2, 2021, 1:01:01 AM9/2/21
to golang-nuts
If you already ran `go mod vendor` outside of docker then there's no need for multilayer caching

COPY . .
RUN go build 

Chris Burkert

unread,
Sep 2, 2021, 1:30:12 PM9/2/21
to K Prayogo, golang-nuts
Would it help to set up your own module proxy e.g. with 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a377ced9-16ce-4862-9478-70c2b10b4280n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages