<legend id='K0GLL'><style id='K0GLL'><dir id='K0GLL'><q id='K0GLL'></q></dir></style></legend>
      <bdo id='K0GLL'></bdo><ul id='K0GLL'></ul>
    <tfoot id='K0GLL'></tfoot>

    <small id='K0GLL'></small><noframes id='K0GLL'>

    <i id='K0GLL'><tr id='K0GLL'><dt id='K0GLL'><q id='K0GLL'><span id='K0GLL'><b id='K0GLL'><form id='K0GLL'><ins id='K0GLL'></ins><ul id='K0GLL'></ul><sub id='K0GLL'></sub></form><legend id='K0GLL'></legend><bdo id='K0GLL'><pre id='K0GLL'><center id='K0GLL'></center></pre></bdo></b><th id='K0GLL'></th></span></q></dt></tr></i><div id='K0GLL'><tfoot id='K0GLL'></tfoot><dl id='K0GLL'><fieldset id='K0GLL'></fieldset></dl></div>

        如何使用多阶段构建减小 python (docker) 图像大小

        时间:2023-09-10
          • <i id='z97T2'><tr id='z97T2'><dt id='z97T2'><q id='z97T2'><span id='z97T2'><b id='z97T2'><form id='z97T2'><ins id='z97T2'></ins><ul id='z97T2'></ul><sub id='z97T2'></sub></form><legend id='z97T2'></legend><bdo id='z97T2'><pre id='z97T2'><center id='z97T2'></center></pre></bdo></b><th id='z97T2'></th></span></q></dt></tr></i><div id='z97T2'><tfoot id='z97T2'></tfoot><dl id='z97T2'><fieldset id='z97T2'></fieldset></dl></div>
            <tfoot id='z97T2'></tfoot>

              <bdo id='z97T2'></bdo><ul id='z97T2'></ul>
            • <small id='z97T2'></small><noframes id='z97T2'>

              <legend id='z97T2'><style id='z97T2'><dir id='z97T2'><q id='z97T2'></q></dir></style></legend>

                    <tbody id='z97T2'></tbody>

                1. 本文介绍了如何使用多阶段构建减小 python (docker) 图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在寻找一种使用 python 和 Dockerfile 创建多阶段构建的方法:

                  I am looking for a way to create multistage builds with python and Dockerfile:

                  例如,使用以下图片:

                  第一张图片:安装所有编译时要求,并安装所有需要的 python 模块

                  1st image: install all compile-time requirements, and install all needed python modules

                  第二个映像:将所有已编译/构建的包从第一个映像复制到第二个映像,不包括编译器本身(gcc、postgers-dev、python-dev 等)

                  2nd image: copy all compiled/built packages from the first image to the second, without the compilers themselves (gcc, postgers-dev, python-dev, etc..)

                  最终目标是拥有一个更小的镜像,运行 python 和我需要的 python 包.

                  The final objective is to have a smaller image, running python and the python packages that I need.

                  简而言之:我如何包装"在第一个图像中创建的所有已编译模块(站点包/外部库),并将它们复制到干净"中方式,到第二张图片.

                  In short: how can I 'wrap' all the compiled modules (site-packages / external libs) that were created in the first image, and copy them in a 'clean' manner, to the 2nd image.

                  推荐答案

                  好的,所以我的解决方案是使用wheel,它允许我们在第一个映像上编译,为所有依赖项创建wheel文件并将它们安装在第二个映像中,而无需安装编译器

                  ok so my solution is using wheel, it lets us compile on first image, create wheel files for all dependencies and install them in the second image, without installing the compilers

                  FROM python:2.7-alpine as base
                  
                  RUN mkdir /svc
                  COPY . /svc
                  WORKDIR /svc
                  
                  RUN apk add --update 
                      postgresql-dev 
                      gcc 
                      musl-dev 
                      linux-headers
                  
                  RUN pip install wheel && pip wheel . --wheel-dir=/svc/wheels
                  
                  FROM python:2.7-alpine
                  
                  COPY --from=base /svc /svc
                  
                  WORKDIR /svc
                  
                  RUN pip install --no-index --find-links=/svc/wheels -r requirements.txt
                  

                  您可以在以下博客文章中看到我对此的回答

                  You can see my answer regarding this in the following blog post

                  https://www.blogfoobar.com/post/2018/02/10/python-and-docker-multistage-build

                  这篇关于如何使用多阶段构建减小 python (docker) 图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Docker Django 404 用于 web 静态文件,但适用于管理静 下一篇:如何在 docker 上运行我的 python 脚本?

                  相关文章

                  最新文章

                  1. <i id='1b4h6'><tr id='1b4h6'><dt id='1b4h6'><q id='1b4h6'><span id='1b4h6'><b id='1b4h6'><form id='1b4h6'><ins id='1b4h6'></ins><ul id='1b4h6'></ul><sub id='1b4h6'></sub></form><legend id='1b4h6'></legend><bdo id='1b4h6'><pre id='1b4h6'><center id='1b4h6'></center></pre></bdo></b><th id='1b4h6'></th></span></q></dt></tr></i><div id='1b4h6'><tfoot id='1b4h6'></tfoot><dl id='1b4h6'><fieldset id='1b4h6'></fieldset></dl></div>
                  2. <tfoot id='1b4h6'></tfoot>
                  3. <legend id='1b4h6'><style id='1b4h6'><dir id='1b4h6'><q id='1b4h6'></q></dir></style></legend>
                  4. <small id='1b4h6'></small><noframes id='1b4h6'>

                      • <bdo id='1b4h6'></bdo><ul id='1b4h6'></ul>