Docker conda多级映像,conda-pack错误

cigdeys3  于 2023-03-22  发布在  Docker
关注(0)|答案(1)|浏览(571)

我尝试在MacOS上使用conda-pack和以下Dockerfile为python conda项目创建一个多级Docker映像:

### build stage
FROM continuumio/miniconda3 AS build
COPY environment.yaml .

# Create the conda environment and install conda-pack
RUN conda env create -f environment.yaml
RUN conda install -c conda-forge conda-pack

# Use conda-pack to create a standalone enviornment in /venv:
RUN conda-pack -n test -o /tmp/env.tar && \
  mkdir /venv && cd /venv && tar xf /tmp/env.tar && \
  rm /tmp/env.tar

RUN /venv/bin/conda-unpack

### runtime stage
# Use the official Miniconda3 image as the base image
FROM continuumio/miniconda3

# Copy /venv from the previous stage:
COPY --from=build /venv /venv

下面是environment.yaml文件:

name: test

dependencies:
  - python=3.8.10
  - pip=20.3
  - pip:
    - setuptools==59.5.0

因此,我得到以下错误:

> [build 5/6] RUN conda-pack -n test -o /tmp/env.tar &&   mkdir /venv && cd /venv && tar xf /tmp/env.tar &&   rm /tmp/env.tar:                                                                                                                                                 
#9 2.287 Collecting packages...                                                                                                                                                                                                                                                 
#9 2.287 CondaPackError:                                                                                                                                                                                                                                                        
#9 2.287 Files managed by conda were found to have been deleted/overwritten in the                                                                                                                                                                                              
#9 2.287 following packages:
#9 2.287 
#9 2.287 - setuptools 65.6.3:
#9 2.287     lib/python3.8/site-packages/pkg_resources/_vendor/__pycache__/zipp.cpython-38.pyc
#9 2.287     lib/python3.8/site-packages/pkg_resources/_vendor/importlib_resources/__init__.py
#9 2.287     lib/python3.8/site-packages/pkg_resources/_vendor/importlib_resources/__pycache__/__init__.cpython-38.pyc
#9 2.287     + 187 others
#9 2.287 
#9 2.287 This is usually due to `pip` uninstalling or clobbering conda managed files,
#9 2.287 resulting in an inconsistent environment. Please check your environment for
#9 2.287 conda/pip conflicts using `conda list`, and fix the environment by ensuring
#9 2.287 only one version of each package is installed (conda preferred).

它看起来有一个问题与版本59.5.0的setuptools,我试图安装与pip...我只得到错误时,使用conda-pack,但在同一时间,这是我发现的方式,我应该能够减少图像大小。
我已经尝试重新安装conda(当前conda版本为23.1.0),但仍然出现错误。我该如何解决?我的目标是能够构建Conda项目的多级Docker映像,并使用conda-pack来降低Docker映像的大小。

nmpmafwu

nmpmafwu1#

conda方法的多阶段docker构建的要点是不再需要在运行时映像中安装condapython
然而,你使用conda作为运行时镜像,它将重新安装你试图解压缩的所有库,我猜如果你把运行时镜像切换到更轻的版本(ubuntu,debian,alpine等),它会运行得很好。
至于上面看到的问题,在conda-pack命令中添加--ignore-missing-files标志可能会解决这个问题。

相关问题