您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

有没有一种方法可以将Python程序编译为二进制文件,并与Scratch Dockerfile一起使用?

有没有一种方法可以将Python程序编译为二进制文件,并与Scratch Dockerfile一起使用?

因此,答案是使用Google的坚决形象。他们在github上有一个示例,我对其进行了如下稍微的编辑:

@H_301_3@# Build a virtualenv using the appropriate Debian release
# * Install python3-venv for the built-in python3 venv module (not installed by default)
# * Install gcc libpython3-dev to compile C Python modules
# * Update pip to support bdist_wheel
FROM debian:buster-slim AS build
RUN apt-get update && \
    apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
    python3 -m venv /venv && \
    /venv/bin/pip install --upgrade pip

# Build the virtualenv as a separate step: Only re-execute this step when requirements.txt changes
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt

# Copy the virtualenv into a distroless image
FROM gcr.io/distroless/python3-debian10
COPY --from=build-venv /venv /venv
COPY . /app
WORKDIR /app
ENTRYPOINT ["/venv/bin/python3", "hello.py"]

如果有人想知道,只需发布??此内容即可。绝对是一件很酷的事情。

链接到Google Distroless图片

影片对我有很大帮助

python 2022/1/1 18:34:17 有237人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶