-
依賴檔案和實際的程式碼檔案單獨分層
-
團隊/公司採用公共的基礎映象等
FROM scratch
ADD alpine-minirootfs-20190228-x86_64.tar.gz /
CMD ["/bin/sh"]
alpine latest 5cb3aa00f899 3 weeks ago 5.53MB
debian latest 0af60a5c6dd0 3 weeks ago 101MB
ubuntu 18.04 47b19964fb50 7 weeks ago 88.1MB
ubuntu latest 47b19964fb50 7 weeks ago 88.1MB
alpine 3.8 3f53bb00af94 3 months ago 4.41MB
ruby latest a5d26127d8d0 4 weeks ago 881MB
ruby alpine 8d8f7d19d1fa 4 weeks ago 47.8MB
ruby slim 58dd4d3c99da 4 weeks ago 125MB
# dockerfile 1
FROM alpine
RUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zip && rm 1.0.0.zip
# dockerfile 2
FROM alpine
RUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zip
RUN rm 1.0.0.zip
# dockerfile 3
FROM alpine
RUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zip && rm 1.0.0.zip
test 3 351a80e99c22 5 seconds ago 5.53MB
test 2 ad27e625b8e5 49 seconds ago 6.1MB
test 1 165e2e0df1d3 About a minute ago 6.1MB
# 使用golang映象作為builder映象
FROM golang:1.12 as builder
WORKDIR /go/src/github.com/go/helloworld/
COPY app.go .
RUN go build -o app .
# 編譯完成之後使用alpine映象作為最終的基礎映象
FROM alpine:latest as prod
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# 從builder中複製編譯好的二進位制檔案
COPY --from=builder /go/src/github.com/go/helloworld/app .
CMD ["./app"]
# ubuntu
apt-get install -y — no-install-recommends
#alpine
apk add --no-cache && apk del build-dependencies
# centos
yum install -y ... && yum clean all
bundle install --without development:test:assets -j4 --retry 3 --path=vendor/bundle \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf vendor/bundle/ruby/2.5.0/cache/*.gem \
&& find vendor/bundle/ruby/2.5.0/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/2.5.0/gems/ -name "*.o" -delete
rm -rf node_modules tmp/cache app/assets vendor/assets spec
-
https://yeasy.gitbooks.io/docker_practice/image/multistage-builds/#%E5%A4%9A%E9%98%B6%E6%AE%B5%E6%9E%84%E5%BB%BA
-
https://github.com/wagoodman/dive
-
https://github.com/docker-slim/docker-slim
-
https://github.com/jwilder/docker-squash
朋友會在“發現-看一看”看到你“在看”的內容