Last active
August 25, 2018 15:06
-
-
Save spurti-chopra/1c0c0c2bf4a63f483f44fe7d0b93595f to your computer and use it in GitHub Desktop.
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
### Below is used for representation purpose and is not in any way a working Dockerfile. | |
FROM alpine:latest | |
RUN apk update && apk add --no-cache gcc musl-dev | |
COPY <prg>.c . | |
RUN gcc -static -o <prg> <prg>.c | |
FROM alpine:latest | |
COPY --from=0 <prg> /usr/bin/<prg> | |
ENTRYPOINT ["/usr/bin/<prg>"] | |
### Alternatively use scratch rather than alpine | |
FROM scratch | |
COPY --from=0 <prg> /usr/bin/<prg> | |
ENTRYPOINT ["/usr/bin/<prg>"] |
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
### Below is used for representation purpose and is not in any way a working Dockerfile. | |
FROM golang:alpine AS builder | |
COPY . /src | |
RUN cd /src && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o <prg-binary> | |
FROM alpine | |
COPY --from=builder /src/<prg-binary> /app/ | |
ENTRYPOINT ["/app/<prg-binary>"] | |
### Alternatively use scratch rather than alpine | |
FROM scratch | |
COPY --from=builder /src/<prg-binary> /src/<prg-binary> | |
ENTRYPOINT ["/src/<prg-binary>"] | |
### NOTE: Usage of scratch led to 4.41 MB reduction in size when compared to alpine |
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
### Below is used for representation purpose and is not in any way a working Dockerfile. | |
### Here, we are using jdk to compile the program, but in order to run we just reuqire jre and not full blown jdk. | |
FROM java:openjdk-8-jdk-alpine | |
COPY <prg>.java . | |
RUN javac <prg>.java | |
FROM java:openjdk-8-jre-alpine | |
COPY --from=0 <prg>.class . | |
CMD java <prg> | |
### NOTE: Image size reduces by around 40 MB by just moving from jdk to jre. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment