Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create minimal docker-image for rust binary #2244

Open
ineiti opened this issue Sep 2, 2024 · 1 comment
Open

Create minimal docker-image for rust binary #2244

ineiti opened this issue Sep 2, 2024 · 1 comment
Labels
feature New feature or request triage Issue needs triage

Comments

@ineiti
Copy link

ineiti commented Sep 2, 2024

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.

@ineiti ineiti added feature New feature or request triage Issue needs triage labels Sep 2, 2024
@ineiti
Copy link
Author

ineiti commented Sep 3, 2024

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage Issue needs triage
Development

No branches or pull requests

1 participant