Docker 镜像制作教程:针对不同语言的精简策略

基础镜像选择

  • alpine(musl libc)
  • slim(debian + glibc)
  • scratch(null)
  • busybox:glibc

Go

FROM golang:alpine
COPY hello.go .
RUN go build hello.go

FROM alpine
COPY --from=0 /go/hello .
CMD ["./hello"]

C

FROM alpine
RUN apk add build-base
COPY hello.c .
RUN gcc -o hello hello.c

FROM alpine
COPY --from=0 hello .
CMD ["./hello"]

Java

openjdk:8-jdk-slim
openjdk:8-jre-slim
openjdk:11-jdk-slim
openjdk:11-jre-slim

Rust

Ubuntu/Debian/Fedora
rust:alpine
scratch
posted @ 2021-08-20 11:05  Varden  阅读(79)  评论(0编辑  收藏  举报