<tfoot id='OUqXQ'></tfoot>

  • <small id='OUqXQ'></small><noframes id='OUqXQ'>

        <bdo id='OUqXQ'></bdo><ul id='OUqXQ'></ul>
        <legend id='OUqXQ'><style id='OUqXQ'><dir id='OUqXQ'><q id='OUqXQ'></q></dir></style></legend>
        <i id='OUqXQ'><tr id='OUqXQ'><dt id='OUqXQ'><q id='OUqXQ'><span id='OUqXQ'><b id='OUqXQ'><form id='OUqXQ'><ins id='OUqXQ'></ins><ul id='OUqXQ'></ul><sub id='OUqXQ'></sub></form><legend id='OUqXQ'></legend><bdo id='OUqXQ'><pre id='OUqXQ'><center id='OUqXQ'></center></pre></bdo></b><th id='OUqXQ'></th></span></q></dt></tr></i><div id='OUqXQ'><tfoot id='OUqXQ'></tfoot><dl id='OUqXQ'><fieldset id='OUqXQ'></fieldset></dl></div>
      1. 将 Python 诗歌与 Docker 集成

        时间:2023-09-10
          <bdo id='8pVOf'></bdo><ul id='8pVOf'></ul>
          <tfoot id='8pVOf'></tfoot>
              <tbody id='8pVOf'></tbody>

                <small id='8pVOf'></small><noframes id='8pVOf'>

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

                1. <legend id='8pVOf'><style id='8pVOf'><dir id='8pVOf'><q id='8pVOf'></q></dir></style></legend>

                2. 本文介绍了将 Python 诗歌与 Docker 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  你能给我一个 Dockerfile 的例子,我可以从 poetry.lockpyproject.toml 从 Docker 进入我的镜像/容器?

                  Can you give me an example of a Dockerfile in which I can install all the packages I need from poetry.lock and pyproject.toml into my image/container from Docker?

                  推荐答案

                  poetrydocker 一起使用时要记住几件事.

                  There are several things to keep in mind when using poetry together with docker.

                  poetry的官方安装方式是通过:

                  Official way to install poetry is via:

                  curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
                  

                  这种方式允许 poetry 及其依赖项与您的依赖项隔离.但是,在我看来,这不是一件好事,原因有两个:

                  This way allows poetry and its dependencies to be isolated from your dependencies. But, in my point of view, it is not a very good thing for two reasons:

                  1. poetry 版本可能会得到更新,它会破坏你的构建.在这种情况下,您可以指定 POETRY_VERSION 环境变量.安装人员会尊重它
                  2. 我不喜欢将互联网上的东西通过管道传输到我的容器中,而不受任何可能的文件修改的保护
                  1. poetry version might get an update and it will break your build. In this case you can specify POETRY_VERSION environment variable. Installer will respect it
                  2. I do not like the idea to pipe things from the internet into my containers without any protection from possible file modifications

                  所以,我使用 pip install 'poetry==$POETRY_VERSION'.如您所见,我仍然建议您固定您的版本.

                  So, I use pip install 'poetry==$POETRY_VERSION'. As you can see, I still recommend to pin your version.

                  另外,将此版本也固定在您的 pyproject.toml 中:

                  Also, pin this version in your pyproject.toml as well:

                  [build-system]
                  # Should be the same as `$POETRY_VERSION`:
                  requires = ["poetry>=1.0"]
                  build-backend = "poetry.masonry.api"
                  

                  它将保护您免受本地和 docker 环境之间的版本不匹配.

                  It will protect you from version mismatch between your local and docker environments.

                  我们希望缓存我们的需求,并且仅在 pyproject.tomlpoetry.lock 文件更改时重新安装它们.否则构建会很慢.为了实现工作缓存层,我们应该把:

                  We want to cache our requirements and only reinstall them when pyproject.toml or poetry.lock files change. Otherwise builds will be slow. To achieve working cache layer we should put:

                  COPY poetry.lock pyproject.toml /code/
                  

                  poetry 安装后,但在添加任何其他文件之前.

                  After the poetry is installed, but before any other files are added.

                  接下来要记住的是virtualenv 创建.我们在 docker 中不需要它.它已经被隔离了.因此,我们使用 poetry config virtualenvs.create false 设置将其关闭.

                  The next thing to keep in mind is virtualenv creation. We do not need it in docker. It is already isolated. So, we use poetry config virtualenvs.create false setting to turn it off.

                  如果你和我一样在开发和生产中使用相同的Dockerfile,你需要根据一些环境变量安装不同的依赖集:

                  If you use the same Dockerfile for both development and production as I do, you will need to install different sets of dependencies based on some environment variable:

                  poetry install $(test "$YOUR_ENV" == production && echo "--no-dev")
                  

                  这种方式 $YOUR_ENV 将控制将安装哪些依赖项集:全部(默认)或仅带有 --no-dev 标志的生产.

                  This way $YOUR_ENV will control which dependencies set will be installed: all (default) or production only with --no-dev flag.

                  您可能还想添加更多选项以获得更好的体验:

                  You may also want to add some more options for better experience:

                  1. --no-interaction 不问任何交互式问题
                  2. --no-ansi 标志,使您的输出更加日志友好
                  1. --no-interaction not to ask any interactive questions
                  2. --no-ansi flag to make your output more log friendly

                  结果

                  你最终会得到类似的东西:

                  Result

                  You will end up with something similar to:

                  FROM python:3.6.6-alpine3.7
                  
                  ARG YOUR_ENV
                  
                  ENV YOUR_ENV=${YOUR_ENV} 
                    PYTHONFAULTHANDLER=1 
                    PYTHONUNBUFFERED=1 
                    PYTHONHASHSEED=random 
                    PIP_NO_CACHE_DIR=off 
                    PIP_DISABLE_PIP_VERSION_CHECK=on 
                    PIP_DEFAULT_TIMEOUT=100 
                    POETRY_VERSION=1.0.0
                  
                  # System deps:
                  RUN pip install "poetry==$POETRY_VERSION"
                  
                  # Copy only requirements to cache them in docker layer
                  WORKDIR /code
                  COPY poetry.lock pyproject.toml /code/
                  
                  # Project initialization:
                  RUN poetry config virtualenvs.create false 
                    && poetry install $(test "$YOUR_ENV" == production && echo "--no-dev") --no-interaction --no-ansi
                  
                  # Creating folders, and files for a project:
                  COPY . /code
                  

                  您可以在此处找到一个完整的真实示例:wemake-django-template

                  You can find a fully working real-life example here: wemake-django-template

                  • 更新诗歌到1.0

                  这篇关于将 Python 诗歌与 Docker 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:standard_init_linux.go:211: exec 用户进程导致“exec 格式 下一篇:Docker 输入文件并保存在输出中

                  相关文章

                  最新文章

                3. <legend id='40CBf'><style id='40CBf'><dir id='40CBf'><q id='40CBf'></q></dir></style></legend>

                  • <bdo id='40CBf'></bdo><ul id='40CBf'></ul>

                      <small id='40CBf'></small><noframes id='40CBf'>

                    1. <tfoot id='40CBf'></tfoot>

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