惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
博客园 - 【当耐特】
博客园_首页
The GitHub Blog
The GitHub Blog
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
D
Docker
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
小众软件
小众软件
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky

ashishb.net

A day in Luxembourg - the richest country in the world I was asked to install malware during a fake interview Book summary: Breakneck - China's quest to engineer the future by Dan Wang Book summary: How to Teach Your Baby to Read Book Summary: The Discontented Little Baby Book by Pamela Douglas Introducing Amazing Sandbox - run third-party tools and AI agents securely on your machine Why software outsourcing gets a bad reputation? Book summary: The Natural Baby Sleep Solution by Polly Moore A day in Antwerp, Belgium Journey of online influencers Two days in Brussels, Belgium Shortcuts - when we love them and when we don't A visit to Rakhigarhi Three days in overhyped Paris Empty Japan, crowded Tokyo The real lock-in in GitHub is not the code, but the stars 11-day Norwegian Breakaway East Caribbean cruise Sanskrit and Sri Lankan Air Force Use REST with Open API The Achilles heel of American capitalism Costa Rica in 4 days At a juice stall in Sri Lanka A short stay at Warsaw, Poland Best practices for using Python & uv inside Docker Two days in Vilnius, Lithuania How IntelliJ IDEs waste disk space Pregnancy Why there aren't many digital nomads from India Two days in Riga, Latvia To keep your machine secure, run third-party tools inside Docker
Docker: Be careful about the scratch image
Ashish Bhatia · 2020-12-09 · via ashishb.net

After I wrote my previous post, some suggested that I can cut down the image size further by using a “scratch” image. And that’s true, “scratch i"s a reserved 0-sized image with nothing in it. And utilizing a scratch binary image did cut down the size of the final Docker image from 13MB to 7.5MB. Pretty good, right? Except the image cannot do an SSL cert verification because of the missing SSL certs!!!

1
Failed to reach google.com: Get https://google.com: x509: certificate signed by unknown authority

The fix was relatively easy. Build ca-certificates in the builder phase. Another thing to add during the builder phase is the timezone data.

1
2
3
4
RUN apk add --no-cache ca-certificates
# Alpine doesn't have tzdata installed by default.
# We need timezone information for parsing dates.
RUN apk add --no-cache tzdata

And copy these over in the run phase.

1
2
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo

The final image is about 0.2 MB larger, and the problem is fixed. See the final code here.

But, what else is in the 5 MB alpine docker image?

The images are from https://github.com/alpinelinux/docker-alpine and check its content. There are tons of standard shell utilities like “ls” symlinked to “busybox”, alpine package database (/apk), other standard libraries for C, SSL. Here are the biggest contributors to size.

1
2
3
4
5
6
-rwxr-xr-x  0 0      0      100144 Aug 26  2019 ./lib/libz.so.1.2.11
-rw-r--r--  0 0      0      215579 Mar  5 08:00 ./etc/ssl/certs/ca-certificates.crt
-rwxr-xr-x  0 0      0      523728 Apr 21 08:35 ./lib/libssl.so.1.1
-rwxr-xr-x  0 0      0      596528 Apr 12 04:06 ./lib/ld-musl-x86_64.so.1
-rwxr-xr-x  0 0      0      841288 Mar 29 12:43 ./bin/busybox
-rwxr-xr-x  0 0      0     2597536 Apr 21 08:35 ./lib/libcrypto.so.1.1

I think it is OK to use scratch as long as you are building a static binary and copying root certificates. I, personally, feel that it’s better to use a 5MB larger alpine Linux image with no surprises.