Last active
November 26, 2024 01:46
-
-
Save piccaso/758e4d41f87d6f07e8dad06825cd4a1a to your computer and use it in GitHub Desktop.
gcc docker image from scratch
This file contains hidden or 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 alpine AS builder | |
RUN apk add --no-cache build-base | |
RUN printf '#include <stdio.h>\nint main() {printf("Hello Container!\\n"); return 0;}\n' > main.c | |
RUN gcc -o main main.c -static | |
FROM scratch | |
COPY --from=builder main . | |
CMD ["./main"] |
This file contains hidden or 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 alpine AS builder | |
RUN apk add --no-cache curl xz build-base | |
RUN cd /usr/local/bin && curl -sSLo- https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-amd64_linux.tar.xz | tar -Jxvf- --strip-components=1 upx-4.2.4-amd64_linux/upx | |
RUN printf '#include <unistd.h>\nvoid _start(void){write(1,"Hello world!", 12);_exit(0);}' > main.c | |
RUN gcc -nostartfiles -o main main.c -s -static | |
RUN upx --best --brute main | |
FROM scratch | |
COPY --from=builder main . | |
CMD ["./main"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment