Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does pyinstaller have any parameters like gcc -static?

I have a similar question to this : Is there a way to compile a Python program to binary and use it with a Scratch Dockerfile?

In this page, I saw that someone said that a C application runs well when compiled with -static.

So I have a new question: does pyinstaller have any parameters like gcc -static to make a python application run well in a Scratch Docker image?

like image 741
lanhao945 Avatar asked Sep 17 '25 14:09

lanhao945


1 Answers

From the question Docker Minimal Image PyInstaller Binary File?'s commands,I get the links about how to make python binary to static,which like the go application demo,say hello world in scratch.

And I do a single ,easy demo,app.py:

print("test")

Then,do docker build with the Dockerfile:

FROM bigpangl/python:3.6-slim AS complier
WORKDIR /app
COPY app.py ./app.py

RUN apt-get update \
    && apt-get install -y build-essential patchelf \
    && pip install staticx pyinstaller \ 
    && pyinstaller -F app.py \
    && staticx /app/dist/app  /tu2k1ed

FROM scratch
WORKDIR /
COPY --from=complier /tu2k1ed /
COPY --from=complier /tmp /tmp
CMD ["/tu2k1ed"]

Get the image below, just 7.22M(I am not sure if could see the pic):

enter image description here

Try to run by code docker run test,successfully:

enter image description here

PS:

With my tests

  • the CMD must write by ['xxx'] not xxx direct.

  • /tmp directory is required in the demo.

  • other python application not test ,jsut the demo codes about print

like image 115
lanhao945 Avatar answered Sep 19 '25 04:09

lanhao945