
-
依賴檔案和實際的程式碼檔案單獨分層
-
團隊/公司採用公共的基礎映象等
FROM scratchADD alpine-minirootfs-20190228-x86_64.tar.gz /CMD ["/bin/sh"]
alpine latest 5cb3aa00f899 3 weeks ago 5.53MBdebian latest 0af60a5c6dd0 3 weeks ago 101MBubuntu 18.04 47b19964fb50 7 weeks ago 88.1MBubuntu latest 47b19964fb50 7 weeks ago 88.1MBalpine 3.8 3f53bb00af94 3 months ago 4.41MB
ruby latest a5d26127d8d0 4 weeks ago 881MBruby alpine 8d8f7d19d1fa 4 weeks ago 47.8MBruby slim 58dd4d3c99da 4 weeks ago 125MB
# dockerfile 1FROM alpineRUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zip && rm 1.0.0.zip# dockerfile 2FROM alpineRUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zipRUN rm 1.0.0.zip# dockerfile 3FROM alpineRUN wget https://github.com/mohuishou/scuplus-wechat/archive/1.0.0.zip && rm 1.0.0.zip
test 3 351a80e99c22 5 seconds ago 5.53MBtest 2 ad27e625b8e5 49 seconds ago 6.1MBtest 1 165e2e0df1d3 About a minute ago 6.1MB
# 使用golang映象作為builder映象FROM golang:1.12 as builderWORKDIR /go/src/github.com/go/helloworld/COPY app.go .RUN go build -o app .# 編譯完成之後使用alpine映象作為最終的基礎映象FROM alpine:latest as prodRUN apk --no-cache add ca-certificatesWORKDIR /root/# 從builder中複製編譯好的二進位制檔案COPY --from=builder /go/src/github.com/go/helloworld/app .CMD ["./app"]
# ubuntuapt-get install -y — no-install-recommends#alpineapk add --no-cache && apk del build-dependencies# centosyum 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
知識星球
朋友會在“發現-看一看”看到你“在看”的內容