docker 多阶段构建测试
[root@localhost ~]# cat app.go
package main
import "fmt"
func main() {
var sta string = "hello word!"
fmt.Println(sta)
}
[root@localhost ~]# cat Dockerfile
FROM golang:latest WORKDIR /go/src/github.com/alexellis/href-counter/ ENV GO111MODULE=on ARG GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io RUN go get -d -v golang.org/x/net/html COPY app.go . ENV GO111MODULE=auto RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=0 /go/src/github.com/alexellis/href-counter/app . CMD ["./app"]

浙公网安备 33010602011771号