dongmou9260 2017-08-25 06:18
浏览 231
已采纳

获取Docker内部所有Go依赖包

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

WORKDIR /app
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.

  • 写回答

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 https://docs.docker.com/engine/userguide/eng-image/multistage-build/ and in more detail https://blog.alexellis.io/mutli-stage-docker-builds/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的