Docker's multi stage build from golfing to alpine example.
507
Docker's multi stage build from golfing to alpine example.
FROM golang:1.8 AS go
MAINTAINER peccu <[email protected]>
COPY ./main.go /go/src/hello-world/main.go
RUN set -x ; \
cd $GOPATH/src/hello-world \
&& go build
FROM alpine:latest
COPY --from=go /go/src/hello-world/hello-world /hello-world
CMD ["/hello-world"]
$ docker build -t tag-name:latest .
$ docker run --rm -it tag-name:latest
Hello, World!
FROM golang:1.8 AS go
MAINTAINER peccu <[email protected]>
COPY ./main.go /go/src/hello-world/main.go
RUN set -x ; \
cd $GOPATH/src/hello-world \
&& go build
CMD ["/go/src/hello-world/hello-world"]
$ docker build -t tag-name:no-multistage .
FROM golang:1.8 AS go
MAINTAINER peccu <[email protected]>
COPY ./main.go /go/src/hello-world/main.go
RUN set -x ; \
cd $GOPATH/src/hello-world \
&& go build
FROM alpine:latest
COPY --from=go /go/src/hello-world/hello-world /hello-world
CMD ["/hello-world"]
$ docker build -t tag-name:latest .
$ docker images tag-name
REPOSITORY TAG IMAGE ID CREATED SIZE
tag-name no-multi eb60933115c3 8 minutes ago 715MB
tag-name latest 3ee4098b1948 17 minutes ago 5.7MB
Content type
Image
Digest
Size
2.6 MB
Last updated
about 8 years ago
docker pull peccu/go-docker-alpine