Create minimal docker-image for rust binary
What problem are you trying to solve?
I want to create a minimal docker image to put my rust binary into. Usually one can do something like this for a minimal docker image:
https://dev.to/deciduously/use-multi-stage-docker-builds-for-statically-linked-rust-binaries-3jgd
Unfortunately, if I do the same with a devbox Dockerfile generated with devbox generate dockerfile, and copy the binary into a base Debian or Ubuntu image, I get something like:
failed to open elf at /nix/store/5adwdl39g3k9a2j0qadvirnliv4r7pwd-glibc-2.39-52/lib/ld-linux-x86-64.so.2
What solution would you like?
I would like to be able to do something similar with the link above, where the devbox-dockerfile builds the rust binary, and then I can copy the binary in a fresh Dockerimage with nothing else.
Alternatives you've considered
I tried various other base-images like Debian, Ubuntu, jetpackio/devbox (without the installation part), but of course they don't work, as the rust binary is linked against the /nix/store/... glibc library.
OK, this is my current solution to the problem:
https://github.com/ineiti/fledger/blob/main/Dockerfile.fledger
It takes the binary created by rust in devbox, uses patchelf to change the interpreter to the debian glibc, and creates a minimal docker image (including the certificates). This makes it 30MB instead of 980MB. I'd say it's a success :)
Of course I'd be happy to have a less patchy solution...