Skip to content

Instantly share code, notes, and snippets.

@piccaso
Last active November 26, 2024 01:46
Show Gist options
  • Save piccaso/758e4d41f87d6f07e8dad06825cd4a1a to your computer and use it in GitHub Desktop.
Save piccaso/758e4d41f87d6f07e8dad06825cd4a1a to your computer and use it in GitHub Desktop.
gcc docker image from scratch
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"]
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