title: go get in Dockerfile. I got cannot find package error
body: <p>I added <code>RUN go get</code> to install packages during &quot;docker-compose&quot;. However, the following <code>cannot find package</code> error was occurred when I run <code>go build</code>. I found that the packages are saved in <code>/go/pkg/linux_amd64/</code>.</p>
  <p><strong>run docker-compose and go build</strong></p>
  <pre><code>$ docker-compose up -d
  $ docker exec -it explorer-cli /bin/bash
  # pwd
  /go
  # ls     
  bin  pkg  src
  # echo $GOPATH
  /go
  # ls /go/pkg/linux_amd64/github.com/
  go-sql-driver
  # go build -i -o /go/bin/explorer-cli src/main.go 
  src/main.go:6:2: cannot find package &quot;github.com/go-sql-driver/mysql&quot; in any of:
      /usr/local/go/src/github.com/go-sql-driver/mysql (from $GOROOT)
      /go/src/github.com/go-sql-driver/mysql (from $GOPATH)
  
  (it worked if I run &quot;go get&quot; manually)
  # go get github.com/go-sql-driver/mysql
  # ls src/
  github.com  main.go
  # go build -i -o /go/bin/explorer-cli src/main.go
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3.4'
  
  services:
    mysql:
      image: mysql:latest
      container_name: database
      volumes:
        - ./docker/:/etc/mysql/conf.d
        - ./docker/:/docker-entrypoint-initdb.d
      environment:
        - MYSQL_RANDOM_ROOT_PASSWORD=true
        - MYSQL_DATABASE=explorer
        - MYSQL_USER=admin
        - MYSQL_PASSWORD=12dlql*41
    app:
      build: .
      tty: true
      image: explorer-cli:latest
      container_name: explorer-cli
      volumes:
        - ./src:/go/src
      external_links:
        - database
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM golang:latest
  
  RUN apt-get update
  RUN apt-get upgrade -y
  
  ENV GOBIN /go/bin
  
  RUN go get github.com/go-sql-driver/mysql
  </code></pre>
  <p><strong>main.go</strong></p>
  <pre><code>package main
  
  import (
      &quot;database/sql&quot;
  
      _ &quot;github.com/go-sql-driver/mysql&quot;
  )
  
  func main() {
      db, err := sql.Open(&quot;mysql&quot;, &quot;XUSER:XXXX@(database:3306)/explorer&quot;)
      if err != nil {
          panic(err.Error())
      }
      defer db.Close()
  }
  </code></pre>
  <hr />
  <p>Update 1</p>
  <p>I noticed big differences between the following directories.</p>
  <pre><code># ls /go/pkg/linux_amd64/github.com/go-sql-driver/
  mysql.a
  
  # ls /go/src/github.com/go-sql-driver/mysql/
  AUTHORS                 connection_go18_test.go packets.go
  CHANGELOG.md            connection_test.go      packets_test.go
  CONTRIBUTING.md         const.go                result.go
  LICENSE                 driver.go               rows.go
  README.md               driver_go18_test.go     statement.go
  appengine.go            driver_test.go          statement_test.go
  benchmark_go18_test.go  dsn.go                  transaction.go
  benchmark_test.go       dsn_test.go             utils.go
  buffer.go               errors.go               utils_go17.go
  collations.go           errors_test.go          utils_go18.go
  connection.go           fields.go               utils_go18_test.go
  connection_go18.go      infile.go               utils_test.go
  </code></pre>
  <hr />
  <p>Update 2</p>
  <p>As @aerokite said, the &quot;volumes&quot; was overwriting the downloaded packages. I changed like the followings and it worked.</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>version: '3.4'
  
  FROM golang:latest
  
  RUN apt-get update
  RUN apt-get upgrade -y
  
  ENV GOBIN /go/bin
  
  RUN go get github.com/go-sql-driver/mysql
  
  RUN mkdir /go/src/explorer-cli
  </code></pre>
  <p><strong>docker-compose</strong></p>
  <pre><code>services:
    mysql:
      image: mysql:latest
      container_name: database
      volumes:
        - ./docker/:/etc/mysql/conf.d
        - ./docker/:/docker-entrypoint-initdb.d
      environment:
        - MYSQL_RANDOM_ROOT_PASSWORD=true
        - MYSQL_DATABASE=explorer
        - MYSQL_USER=XUSER
        - MYSQL_PASSWORD=XXXX
    app:
      build: .
      tty: true
      image: explorer-cli:latest
      container_name: explorer-cli
      volumes:
        - ./src/explorer-cli:/go/src/explorer-cli
      external_links:
        - database
  </code></pre>
  <p><strong>go build</strong></p>
  <pre><code>go build -i -o /go/bin/explorer-cli src/explorer-cli/main.go
  </code></pre>