Search code examples
linuxdockercontainersld-preloadrunc

How to use LD_PRELOAD in container runc


I followed this link and tried to use runc to launch a busybox container. I wanted to load a shared library into the container process with the LD_PRELOAD trick. I modified the args in config.json

        "args": [
                "sh"
        ],

to

        "args": [
                "LD_PRELOAD=preload.so sh"
        ],

It does not work as I expected. Is there a way to load a shared library with runc?


Solution

  • Found a way to preload a shared library with runc:

            "args": [                                                       
                    "sh"                                                  
            ],                                                              
            "env": [                                                        
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "TERM=xterm",                                           
                    "LD_PRELOAD=/usr/lib/x86_64-linux-gnu/init.so"    
            ],