-2

I'm having an unexpected behavior when running go get [module] inside a docker container compared to my local machine and I will appreciate any help to understand the reason for this different behavior.

1) Local machine

Command:

go get github.com/axw/gocov/gocov

Result:

  • $GOPATH/bin contains executable gocov.
  • The module was downloaded into $GOPATH/src/github.com/axw/gocov/gocov.
  • $GOPATH/pkg doesn't contains anything related to gocov package.

2) Docker container

Dockerfile:

This dockerfile is for testing purposes, because of that it doesn't have an entrypoint.

FROM golang:alpine

COPY .  /app
WORKDIR /app

RUN go get -v -u github.com/axw/gocov/gocov
RUN ls $GOPATH/bin
RUN ls -laR / | grep "^\/.*gocov.*$"

Result:

  • $GOPATH/bin contains executable gocov.
  • $GOPATH/src doesn't contains anything related to gocov package.
  • The module was downloaded into $GOPATH/pkg/mod/github.com/axw/gocov@v1.0.0.
fdaines
  • 1,216
  • 10
  • 12
  • 1
    That is the expected result. GOPATH is not used for module source. – JimB Mar 15 '21 at 13:08
  • 1
    You might as well update start working with modules now, as `go get` is being deprecated as a method for building main packages. See https://golang.org/doc/go1.16#go-command on the changes to `go install` and `go get`. If you want the project source, checkout the project with `git`. – JimB Mar 15 '21 at 13:12

1 Answers1

0

From the date your posting this I take that you are running go >= 1.16.0 inside Docker which introduced some changes to the module system (like @JimB commented: See golang.org/doc/go1.16#go-command on the changes to go install and go get). You are probably running an older version of go on your machine.

You can verify this by using following Dockerfile:

FROM golang:1.15
COPY .  /app
WORKDIR /app

RUN go get -v -u github.com/axw/gocov/gocov
RUN ls $GOPATH/bin
RUN ls -laR / | grep "^\/.*gocov.*$"

This will create an image containing the code inside $GOPATH/src.