TODO
Last active
May 12, 2020 18:52
-
-
Save shovanmaity/8523a193a96722008a3c3f7fa16c5051 to your computer and use it in GitHub Desktop.
delete intermediate container images for docker multi-stage build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.13.5 as tester | |
LABEL type=intermediate-container | |
COPY main.go /go/src/main.go | |
COPY Makefile /go/src/Makefile | |
WORKDIR /go/src | |
RUN make test | |
FROM golang:1.13.5 as builder | |
LABEL type=intermediate-container | |
COPY main.go /go/src/main.go | |
COPY Makefile /go/src/Makefile | |
WORKDIR /go/src | |
RUN make build | |
FROM alpine:3.8 as cert | |
LABEL type=intermediate-container | |
RUN apk --update add ca-certificates | |
FROM scratch | |
ENV PATH=/bin | |
COPY --from=builder /go/src/demo /bin/demo | |
COPY --from=cert /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | |
CMD ["demo"] | |
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | |
w.Write([]byte("ok")) | |
}) | |
http.ListenAndServe(":8080", nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: dependency | |
dependency: | |
.PHONY: build | |
build: dependency | |
@GO111MODULE=off CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o demo . | |
.PHONY: test | |
test: dependency | |
@GO111MODULE=off go test ./... | |
.PHONY: image | |
image: dependency | |
@docker build -t demo . | |
.PHONY: prune | |
prune: | |
@docker image prune -f --filter label=type=intermediate-container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment