最新文章

Go Docker 镜像进阶: 精简镜像

Go Docker 镜像进阶: 精简镜像

​[图片来自 https://www.facebook.com/sequenceprocess/]

问题: 入门到生产级的差距

昨天的文章《为 Go 应用创建 Docker 镜像》, 算是入门级的, 并不适用于生产级. 为什么?

$ docker images
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
addozhang/golang-hello-world                  latest              4cce1292a87a        4 seconds ago       813MB

整个镜像的大小有 813MB, 这还只有一个简单的 Hello world. 因为其中包含了 Golang 的编译和运行环境. 但是实际生产环境中, 我们并不需要这么多.

先看结果

精简之后只有 2.07MB, 而且并不影响运行.