Dockerfile 多阶段构建
之前的做法
全部放入一个 Dockerfile
package main
import "fmt"
func main(){
fmt.Printf("Hello World!");
}FROM golang:alpine
RUN apk --no-cache add git ca-certificates
WORKDIR /go/src/github.com/go/helloworld/
COPY app.go .
RUN go get -d -v github.com/go-sql-driver/mysql \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . \
&& cp /go/src/github.com/go/helloworld/app /root
WORKDIR /root/
CMD ["./app"]分散到多个 Dockerfile
使用多阶段构建
只构建某一阶段的镜像
构建时从其他镜像复制文件
Last updated