slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)
Apache License 2.0
19.33k stars 725 forks source link

slim fails loading python modules in build #490

Open gcasale82 opened 1 year ago

gcasale82 commented 1 year ago

I was trying to slim an image that works perfectly , but when running this command : slim build --target mailserver:latest --tag mailserver:slim --exec "python3 mailserver.py" --expose 2025 -http-probe=false --preserve-path /home/pmail/.local/lib/python3.9/site-packagesit seems fails to load the library I installed with pip3 in requirements :

slim[build][exec]: output: Traceback (most recent call last):
slim[build][exec]: output:   File "/home/pmail/mailserver.py", line 4, in <module>
slim[build][exec]: output:     from aiosmtpd.controller import Controller
slim[build][exec]: output: ModuleNotFoundError: No module named 'aiosmtpd'

however if I run the image import is ok :

gcasale@deb-hp-8300:~$ docker attach a40d0f417e0f
pmail@a40d0f417e0f:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from aiosmtpd.controller import Controller
>>> 

how can I solve this issue ?

gcasale82 commented 1 year ago

it worked in this way : slim build --target mailserver:latest --tag mailserver:slim --exec "su -c 'python3 mailserver.py' pmail" --expose 2025 -http-probe=false , was not getting pmail user for running the command.Not taking the USER from Dockerfile , even using option --run-target-as-user