Multi-stage, FROM scratch, w/ networking.

blov · 2017-05-06 21:00:10 · 556 次点击    
这是一个分享于 2017-05-06 21:00:10 的资源,其中的信息可能已经有所发展或是发生改变。

The recent posts about multi-stage docker builds produced containers that were still larger than needed. Likewise, tutorials I've found that start "FROM scratch" copy the ca-certificates.crt file from the local system. Here is a simple dockerfile which should portably produce the smallest container possible while still enabling networking: https://github.com/daved/goecho

FROM golang:1.8.1
ENV APP /app
WORKDIR /go/src${APP}/
COPY *.go .
RUN CGO_ENABLED=0 GOOS=linux; go build -a -tags netgo -
ldflags '-w' -o ${APP}

FROM scratch
ENV CERTS /etc/ssl/certs/ca-certificates.crt
COPY --from=0 ${CERTS} ${CERTS}
COPY --from=0 ${APP} ${APP}
EXPOSE 25000
ENTRYPOINT [ "/app" ]

  • Docker 17.05 was posted to the "edge" release channel for Ubuntu a handful of hours ago. I assume that means it has also hit for other OSes.


评论:

Oliviaruth:

Cool! Is this availible with docker hub automated builds yet?

daveddev:

I think so too, thanks! I wish I could answer whether the above dockerfile is compatible with hub automated builds, but I don't use that feature. Nonetheless, my guess is that any valid dockerfile will work.

:

[deleted]


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

556 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传