Hacker News new | past | comments | ask | show | jobs | submit login

So I was trying to follow along with this and kept getting an error

    /# chroot /testroot /hello
    chroot: failed to run command ‘/hello’: No such file or directory
If anybody was wondering, the trick is to statically link

     gcc hello.c -o hello  -static -static-libgcc
Or, use go for the hello executable



Author here. Sorry, I should have added more instruction there.

What I was expecting someone to do is use the 'pull' command made later to extract a statically linked hello from the hello:latest image, but I didn't explain how until later. So yes, thanks for including this, static linked is the way to go here, or ldd and copying other things in.


Or dynamically link and use ldd to identify and copy libraries the program is linking:

   ldd hello


This is why I build containers using Nix (plus the reproducibility, caching, etc.): since everything has a path containing an unguessable hash, all dependencies must be referred to by their absolute path (either directly, or indirectly via an env var, etc.).

That makes it trivial to find all the dependencies of a file (whether they're dynamic libraries, interpreter packages, image files, etc.), transitively, and tar them all up into a self-contained container :)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: