Does pyinstaller have any parameters like gcc -static?

Viewed 2534
2 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

Related