python - pyinstaller 有 gcc -static 之类的参数吗?
问题描述
我有一个类似的问题:有没有办法将 Python 程序编译为二进制文件并将其与 Scratch Dockerfile 一起使用?
在这个页面中,我看到有人说 C 应用程序在编译时运行良好-static
。
所以我有一个新问题:是否pyinstaller
有任何参数gcc -static
可以让 python 应用程序在 Scratch Docker 映像中运行良好?
解决方案
从问题Docker Minimal Image PyInstaller Binary File? 的命令,我得到了关于如何将 python 二进制转换为静态的链接,就像 go 应用程序演示,从头开始问好世界。
我做了一个简单的演示,app.py:
print("test")
然后,使用 Dockerfile 进行 docker build:
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"]
得到下面的图片,只有 7.22M(我不确定是否能看到图片):
尝试通过代码运行docker run test
,成功:
PS:
通过我的测试
必须
CMD
由 ['xxx'] 而非 xxx 直接写入。/tmp
演示中需要目录。其他 python 应用程序未测试,仅包含有关打印的演示代码
推荐阅读
- reactjs - __WEBPACK_IMPORTED_MODULE_4_react___default.a.memo 不是函数
- apache-spark - 如何仅读取文件的列数而不是行分隔符?
- android - 有没有办法像 Youtube 一样从 Android 发起 Facebook 直播?
- jquery - 如何为 svg 过滤器 feComponentTransfer 设置动画?
- c# - 转换页面的语言
- php - WooCommerce 中可变产品的条件自定义价格后缀
- sql - 更新表中多个属性组合的行
- html - 从 express js 访问 HTML 元素
- java - 如何在自定义执行侦听器中查询组、用户?
- c++ - 如何通过fifo使用protobuf的SerializeToOstream和ParseFromIstream进行IPC?