很多官方 docker 镜像都出了基于 alpine 的版本,相较于正常的版本, alpine 版会有什么坑吗?

2019-07-11 08:57:17 +08:00
 qwerthhusn

如果 alpine 版本的没有任何坑,那么相较于那些基于 Debian,Ubuntu,CentOS 的镜像,有体积大小的绝对优势。 那那些版本还有什么存在的必要?而且很多都会把那些作为默认的(例如 latest ) tag,而 alpine 版的后面还要跟上-alpine 的 tag

22127 次点击
所在节点    Docker
26 条回复
VD
2019-07-11 09:05:30 +08:00
单独的服务有优势,但是如果在一台机子上部署 N 个服务的话,alpine 便没有优势

另外,如果涉及编译的话,alpine 用的是 musl libc,这一点要注意
leo108
2019-07-11 09:15:49 +08:00
相比于 alpine,你提到的那些系统有更加丰富的软件库、系统各种特性用法的普及度更高,在已有镜像基础上去安装新的程序成本更低。
tony1016
2019-07-11 09:16:10 +08:00
拿来单独当服务器也挺好玩的版本,真的很快,还默认源里就有 ss,就是目前还不能支持 virtualbox
Muninn
2019-07-11 09:20:12 +08:00
```
postgres:<version>-alpine
This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

This variant is highly recommended when final image size being as small as possible is desired. The main caveat to note is that it does use musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar).
```

早前很多镜像都有这么一段说明,但是后来发现没什么问题,越来越多的镜像已经去掉这一段了。
gamexg
2019-07-11 09:29:02 +08:00
docker 镜像是共享的,
也就是所有底层是 ubuntu1804 的 nginx、php 镜像共用一个 ubuntu1804,单个看着空间占用大,但是平均起来并没有多少。
所以只要还有一个依赖于 ubuntu,那么其他的即使换成 alpine 并不会减小总空间占用,还会增加 alpine 的占用,意义就不是很大了。

alpine 没用过几次,ubuntu 的库还是比 alpine 齐全,资料也好查。
jonsun30
2019-07-11 09:34:21 +08:00
glibc 换成了 musl 要注意
qwerthhusn
2019-07-11 09:34:23 +08:00
@gamexg 额,也就是说如果有多个容器,使用了同样的镜像,或者使用了不同的景象但是 FROM 是一样的,这时不会占用额外的空间,他们是共享这些镜像里的文件的。但是如果某个容器“不小心”动了里面的文件,会不会影响其他的后果。我准备先试一下
qwerthhusn
2019-07-11 09:37:53 +08:00
@VD
@jonsun30 这个我知道,像有些镜像就没有 alpine 版本,比如 MySQL。但是在作为镜像使用者的时候,我们也许不会太过于关注这两个 C 库的区别的,比如:gLibc 和 muslLibC 的 nginx 或 OpenJDK 有啥差别么
sunny352787
2019-07-11 10:13:24 +08:00
直接使用的话其实没啥区别,区别只在于你要使用它作为自己的镜像的 From 的时候,alpine 版本可能无法提供你所需要的东西
ipwx
2019-07-11 10:19:28 +08:00
@qwerthhusn 不会有其他后果。因为 Docker 的文件系统是一层层叠起来的,每一层都是只读的。

https://medium.com/@nagarwal/docker-containers-filesystem-demystified-b6ed8112a04a
mchl
2019-07-11 10:29:41 +08:00
目前碰到一个坑,就是没有内置信任的 https 根证书
qwerthhusn
2019-07-11 10:42:34 +08:00
@mchl 不太清楚什么意思?? https://hackernoon.com/alpine-docker-image-with-secured-communication-ssl-tls-go-restful-api-128eb6b54f1f

FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY ./mycert.crt /usr/local/share/ca-certificates/mycert.crt
RUN update-ca-certificates
richzhu
2019-07-11 10:49:09 +08:00
我把公司的 k8s 环境中 200+Pod 全都换成了 alpine,跑到现在已经半年了,除了验证码不显示等几个小小坑,其余的坑没有遇到过,同时减少了 docker 仓库和 K8S Node 中的容量占用 总体看起来很值~
WilliamYang
2019-07-11 11:13:50 +08:00
我觉得如果是 python 就没太大必要用了,因为很可能要装一大堆依赖,不但浪费时间,也可能有不可预见的问题,因为 musl,最重要的是得到的镜像大小并没有差别很大
monsterxx03
2019-07-11 11:23:23 +08:00
apline 的 musl 在 /etc/resolv.conf 里不支持全部 option set, 对 dns 有特殊要求的可能有问题.

还有 apline 里面是 busybox, 有些程序如果用 shell 调用一些系统命令, 可能参数不一样会出错(比如 fluentd 的某个版本调用 gzip)
momocraft
2019-07-11 11:34:36 +08:00
> 但是如果多个镜像(包括每个镜像运行的多个容器)使用了同一个基础镜像,是不会花费额外的空间的
> 也就是所有底层是 ubuntu1804 的 nginx、php 镜像共用一个 ubuntu1804

理想情况是这样
实际上 docker hub 的每个镜像的 FROM ubuntu:latest 未必是同一个,几十个 ubuntu:latest 和几十个 alpine:latest 可能会有不小差距
每个 image 都自己从头 build 且统一更新的可以忽略这点
mattx
2019-07-11 11:35:25 +08:00
感觉没啥意义,如果有得选我肯定不愿意用。
jiqing
2019-07-11 12:11:38 +08:00
楼上有朋友说了,是 glibc,所以好多通用软件没法直接用。比如 jdk,当时被坑了一晚上。找了 zulu 专门对 apline 编译过的 openjdk。虽然 alpine 的源里就有。当时没配置好网络,没法用 apk 安装
est
2019-07-11 12:14:51 +08:00
缺 glibc 主要坑就是效率问题。
Imr
2019-07-11 12:15:45 +08:00
alpine 源里东西很全,几乎所有常用的都有,坑我没遇到过,自带 vi,源小装包快优势太多

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/581888

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX