slim icon indicating copy to clipboard operation
slim copied to clipboard

How to exclude a specific binary file from optimization process?

Open ammnt opened this issue 2 months ago • 5 comments

Hello,

How to exclude a specific binary file from optimization process? For example I just want to keep some binary file with path /usr/sbin/run or something like this🤔

Thanks, Best regards

ammnt avatar Oct 08 '25 10:10 ammnt

@ammnt You have a few options. There's a number of --include-* flags you can use.

To make sure you keep a given binary you can use the --include-bin flag where you'd specify the full path to that binary (example: mint slim --target yourappimage:latest --include-bin=/usr/bin/jq). You can use the --include-exe flag if your binary can be found in the PATH environment variable, so you don't have to specify the full path to the app binary (example: mint slim --target yourappimage:latest --include-exe=jq).

The generic --include-path flag can be used to keep a specific file or directory in the output container image. Note that you can't do --include-path=/ to include everything :-)

Alternatively you can run a so called probe that exercises your binary in a call. You can do it with the --exec flag (here's an example that does it for curl: mint slim --target archlinux:latest --http-probe=false --exec "curl checkip.amazonaws.com).

kcq avatar Oct 08 '25 20:10 kcq

@kcq, thanks a lot for your answer👍

ammnt avatar Oct 09 '25 05:10 ammnt

@kcq, I'm sorry, but I still can't preserve netcat binary and healthcheck therefore:

Image

Slim results:

Image

Dive report:

Image

As you see - netcat binary is gone and HEALTHCHECK directive isn't working anymore. What I have to do to fix this?

ammnt avatar Oct 09 '25 09:10 ammnt

I have added this parameters and looks like it works fine now: --preserve-path /usr/bin/nc --include-path /usr/bin/nc --preserve-path /usr/lib/libmd.so.0 --include-path /usr/lib/libmd.so.0 --preserve-path /usr/lib/libbsd.so.0 --include-path /usr/lib/libbsd.so.0

ammnt avatar Oct 09 '25 10:10 ammnt

@ammnt Let me try to repro it with Netcat to see what's going on.

kcq avatar Oct 12 '25 03:10 kcq