$ docker run --rm -v "${PWD}:/work" cgr.dev/chainguard/gcc-glibc examples/hello/main.c -o hello
This will write a Linux binary to ./hello. If you’re on Linux and have the glibc library, you
should be able to run it directly. Otherwise you can run it in a container e.g:
Note: only linux/amd64 is uspported at the moment.
We can also do this all in a multi-stage Dockerfile e.g:
FROM cgr.dev/chainguard/gcc-glibc as build
COPY hello.c /work/hello.c
RUN cc hello.c -o hello
FROM cgr.dev/chainguard/glibc-dynamic
COPY --from=build /work/hello /hello
CMD ["/hello"]
And we can also compile statically to be used in environments without glibc:
FROM cgr.dev/chainguard/gcc-glibc as build
COPY hello.c /work/hello.c
RUN cc --static hello.c -o hello
FROM cgr.dev/chainguard/static
COPY --from=build /work/hello /hello
CMD ["/hello"]