title: Speeding up Go builds with go 1.10 build cache in Docker containers
body: <p>I have a Go project with a large <code>vendor/</code> directory which almost never changes.</p>
  
  <p>I am trying to use the new <a href="https://golang.org/doc/go1.10" rel="noreferrer">go 1.10</a> <strong>build cache</strong> feature to speed up my builds in Docker engine locally.</p>
  
  <p>Avoiding recompilation of my <code>vendor/</code> directory would be enough optimization. So I'm trying to do Go equivalent of this common Dockerfile pattern for Python:</p>
  
  <pre><code>FROM python
  COPY requirements.txt .              # &lt;-- copy your dependency list
  RUN pip install -r requirements.txt  # &lt;-- install dependencies
  COPY ./src ...                       # &lt;-- your actual code (everything above is cached)
  </code></pre>
  
  <p>Similarly I tried:</p>
  
  <pre><code>FROM golang:1.10-alpine
  COPY ./vendor ./src/myproject/vendor
  RUN go build -v myproject/vendor/... # &lt;-- pre-build &amp; cache "vendor/"
  COPY . ./src/myproject
  </code></pre>
  
  <p>However this is giving "cannot find package" error (likely because you cannot build stuff in vendor/ directly normally either).</p>
  
  <p>Has anyone been able to figure this out?</p>