The FROM golang: 1.7.3 WORKDIR/go/src/github.com/alexellis/href-counter/COPY app. Go. RUN go a get - d - v golang.org/x/net/html \ && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  RUN apk --no-cache add ca-certificatesWORKDIR /root/COPY app .CMD ["./app"]  Copy the code

#! /bin/shecho Building alexellis2/href-counter:builddocker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \ -t alexellis2/href-counter:build . -f Dockerfile.builddocker container create --name extract alexellis2/href-counter:build docker container cp extract:/go/src/github.com/alexellis/href-counter/app ./app docker container rm -f extractecho Building alexellis2/href-counter:latestdocker build --no-cache -t alexellis2/href-counter:latest .rm ./app

The FROM golang: 1.7.3 WORKDIR/go/src/github.com/alexellis/href-counter/RUN go a get - d - v golang.org/x/net/html COPY app. Go .RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .FROM alpine:latest RUN apk --no-cache add ca-certificatesWORKDIR /root/COPY --from=0 /go/src/github.com/alexellis/href-counter/app .CMD ["./app"]Copy the code
$ docker build -t app:latest .Copy the code

The FROM golang: 1.7.3 as builderWORKDIR/go/src/github.com/alexellis/href-counter/RUN go get golang.org/x/net/html - d - v COPY app.go .RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .FROM alpine:latest RUN apk --no-cache add ca-certificatesWORKDIR /root/COPY --from=builder /go/src/github.com/alexellis/href-counter/app .CMD ["./app"]Copy the code

$ docker build --target builder -t alexellis2/href-counter:latest .

  • Debug specific build phases

  • In the Debug phase, all debugging or tools are enabled, and in the Production phase, as minimal as possible

  • In the Testing phase, your application populates test data, but in the Production phase, it uses production data

COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.confCopy the code