NYC's Blog - 构建最小的Go程序镜像 的评论 http://niyanchun.com/build-minimal-go-image.html zh-CN 我们知道构建一个Docker镜像的时候往往需要引入一些程序依赖的东西,最常见的就是引入一个基础操作系统镜像,但这样往往会使得编译出来的镜像特别大。但是对于go语言,我们可以使用静态编译的方式构建... Fri, 27 Oct 2017 10:04:58 +0800 Fri, 27 Oct 2017 10:04:58 +0800 AbelLai http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-364 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-364 Fri, 27 Oct 2017 10:04:58 +0800 AbelLai 不错不错,我基本也是这样干的。在生产环境,我使用的是两阶段:第一阶段类似你文章一开始说,从git拉取代码,基于标准的golang docker镜像编译出bin文件(还会跑test之类的);第二阶段则是从第一阶段里面拉取出已经编译好的bin文件以及基于scratch镜像进行第二次构建,得到一个小的镜像。

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-364#comments
NYC http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-283 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-283 Tue, 04 Jul 2017 10:45:50 +0800 NYC 是这样的,Go1.5版本之前,Go里面的一些库函数是用C实现的(网络方面的居多),也就是CGO。如果你的代码中使用了这些C实现的库函数,那你就要加上这个参数,让它编译的时候去CGO里面找,否则编译时会报错。但是Go1.5版本开始实现了自举,所有的标准库都是用Go代码实现,就不存在这个问题了。所以,如果你的Go版本是1.5之前的,最好加上这个参数,当然如果你的代码中没用使用C实现的库,那不加也不会报错。如果你的Go是1.5及之后的版本,就不需要再加这个参数了。

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-283#comments
wmzy http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-282 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-282 Tue, 04 Jul 2017 09:42:15 +0800 wmzy CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .里如果不加这个参数会有什么问题吗?编译的中间结果会有命名冲突吗?

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-282#comments
NYC http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-281 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-281 Tue, 04 Jul 2017 09:27:43 +0800 NYC 可以看一下官方文档:https://golang.org/src/cmd/link/doc.go?h=-installsuffix。其实就是Go 1.5之前的版本里面引用了C代码,所以这个参数就是让编译的时候去链接cgo的库,以免有的库找不到

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-281#comments
wmzy http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-280 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-280 Mon, 03 Jul 2017 18:02:04 +0800 wmzy 请教一下-installsuffix cgo参数的具体含义,多谢

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-280#comments
NYC http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-244 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-244 Fri, 21 Apr 2017 09:02:27 +0800 NYC 不知道你所说的适应性强是不是指其跨平台特性以及没有动态依赖?其实应用容器化更多的是为了方便部署,避免实际中开发环境和生产环境不一致而导致的部署困难,就比如Docker官方的口号就是一处编译,随处运行。但如果没有容器化,那比如在Linux上编译的就没法在Windows或者Mac上面运行。而且,容器化之后还可以对应用所使用的CPU、内存等资源做限制,这些都是容器化之后的可以带来的方便。另外,虽然Go在跨平台方面已经做的很好,但毕竟还是比较偏底层的语言,所以在涉及一些底层的操作时的API并不是在每个平台上面都表现很好,这个你看godoc时有些API就会有说明,一些第三方的库也类似。

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-244#comments
沙隆巴斯 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-243 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-243 Thu, 20 Apr 2017 21:29:25 +0800 沙隆巴斯 go本身就适应性强,真心没想明白还有什么必要放在容器里。

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-243#comments
NYC http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-170 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-170 Tue, 03 Jan 2017 20:32:47 +0800 NYC 2017还要求老司机带呀[嘻嘻]

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-170#comments
老司机 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-169 http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-169 Tue, 03 Jan 2017 14:39:56 +0800 老司机 大神啊。。。2017膝盖献上

]]>
http://niyanchun.com/build-minimal-go-image.html/comment-page-1#comment-169#comments