Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multi stages builds #538

Closed
sylr opened this issue Dec 12, 2017 · 1 comment
Closed

Use multi stages builds #538

sylr opened this issue Dec 12, 2017 · 1 comment

Comments

@sylr
Copy link

sylr commented Dec 12, 2017

Hi,

Current images ship with the building environment it required to build the binaries.

With Docker multi stage builds the result of the build can be copied to a new clean image that does not have the build env with is not required anymore, e.g. :

FROM golang:1.7.3 as builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go 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-certificates
WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]  

With this images will be lighter.

Regards.

@yosifkit
Copy link
Member

The alpine-based php images are made for this exact reason; they are small and remove build dependencies in the layer that they are added to save space. No need to have a multi stage build for that.

For more information on why official-images do not use multi stage builds, see docker-library/official-images#3383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants