2017-08-25 06:18
浏览 205


I can get all my dependent packages when I do the following:

$ cd myrepo
$ go get -d ./...

But what is the best way to do this in docker? I don't want all the repo's inside my docker-app so I'm searching for a way to execute this inside a docker container to some volume (or something like that) and reuse it.

I was thinking about something like. Dockerfile

FROM golang:1.8

ADD ./src

Build image

$ docker build -t myapp .

$ docker run myapp go get -d ./...

How can I reuse the dependencies without pulling/downloading them every time? I want them in a sort of volume. I know docker volumes a bit but I don't know how to use it in this case.

图片转代码服务由CSDN问答提供 功能建议


   $ cd myrepo 
 $ go -d。/ ... 

但是在docker中做到这一点的最佳方法是什么? 我不希望所有回购都在我的docker-app中,因此我正在寻找一种方法可以在docker容器中将其执行到某个卷(或类似的东西)并重复使用。 < p>我在想类似的东西。 Dockerfile

  FROM golang:1.8 
WORKDIR / app 
ADD ./src


  $ docker build -t myapp。
 $ docker run myapp go get -d。/ ... 
 <  / code>  

如何重用依赖项,而不必每次都提取/下载它们? 我希望它们有一定的体积。 我有点了解docker卷,但是在这种情况下我不知道如何使用它。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpang1898 2017-08-25 09:03

    The best way to do this is to use the builder pattern. In the first image you download all the dependencies and build the executable. In the second you copy the executable into a new image. You can use the scratch image as a base, but alpine is maybe better because it is also small but provides a shell and a packet manager for something like certificates for https.

    If you first copy the sources and the install the dependencies, they will be downloaded with every source change, so it ist better to use something like go dep. With it you can copy the Gopkg file, install your dependencies and then copy the sources.

    Official article and in more detail

    解决 无用
    打赏 举报

相关推荐 更多相似问题