在 docker 容器内时,Conda 无法构建

问题描述

我正在尝试构建一个 docker 镜像。这是完整的 dockerfile:

FROM ubuntu

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH

ENV TZ=Europe/athens
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
    libglib2.0-0 libxext6 libsm6 libxrender1 \
    git mercurial subversion

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda2-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \
    /bin/bash ~/miniconda.sh -b -p /opt/conda && \
    rm ~/miniconda.sh && \
    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    echo "conda activate base" >> ~/.bashrc

RUN apt-get install -y curl grep sed dpkg && \
    tini_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && \
    curl -L "https://github.com/krallin/tini/releases/download/v${tini_VERSION}/tini_${tini_VERSION}.deb" > tini.deb && \
    dpkg -i tini.deb && \
    rm tini.deb && \
    apt-get clean

ENTRYPOINT [ "/usr/bin/tini","--" ]
CMD [ "/bin/bash" ]

#SECOND PART
RUN apt install -y libgl1-mesa-glx
RUN conda install conda-build
RUN apt-get install -y git
workdir /
RUN git clone https://github.com/cadquery/cadquery.git
workdir /cadquery
RUN conda env create -n cq -f environment.yml
RUN echo "source activate cq" > ~/.bashrc
ENV PATH /opt/conda/envs/cq/bin:$PATH
workdir /testing

但是,当需要构建 conda 时 - 更具体地说,在第 12 步,这里的这一行:

RUN conda install conda-build

出现错误

似乎是正常安装包,然后失败。:

Proceed ([y]/n)? 
ruamel_yaml-0.15.100 | 268 KB    | ########## | 100% 
readline-8.1         | 464 KB    | ########## | 100% 
bzip2-1.0.8          | 105 KB    | ########## | 100% 
tzdata-2020f         | 123 KB    | ########## | 100% 
xz-5.2.5             | 438 KB    | ########## | 100% 
tk-8.6.10            | 3.2 MB    | ########## | 100% 
conda-build-3.21.4   | 585 KB    | ########## | 100% 
cffi-1.14.5          | 227 KB    | ########## | 100% 
ld_impl_linux-64-2.3 | 645 KB    | ########## | 100% 
urllib3-1.26.4       | 99 KB     | ########## | 100% 
pyyaml-5.4.1         | 180 KB    | ########## | 100% 
pip-21.1.1           | 2.0 MB    | ########## | 100% 
lz4-c-1.9.3          | 216 KB    | ########## | 100% 
beautifulsoup4-4.9.3 | 86 KB     | ########## | 100% 
python-3.9.5         | 22.7 MB   | ########## | 100% 
pkginfo-1.7.0        | 42 KB     | ########## | 100% 
tqdm-4.59.0          | 90 KB     | ########## | 100% 
setuptools-52.0.0    | 880 KB    | ########## | 100% 
python-libarchive-c- | 50 KB     | ########## | 100% 
cryptography-3.4.7   | 1.0 MB    | ########## | 100% 
icu-58.2             | 22.7 MB   | ########## | 100% 
pysocks-1.7.1        | 31 KB     | ########## | 100% 
libxml2-2.9.10       | 1.3 MB    | ########## | 100% 
certifi-2020.12.5    | 143 KB    | ########## | 100% 
openssl-1.1.1k       | 3.8 MB    | ########## | 100% 
libgcc-ng-9.1.0      | 8.1 MB    | ########## | 100% 
patchelf-0.12        | 92 KB     | ########## | 100% 
glob2-0.7            | 12 KB     | ########## | 100% 
idna-2.10            | 52 KB     | ########## | 100% 
liblief-0.10.1       | 2.0 MB    | ########## | 100% 
pycparser-2.20       | 94 KB     | ########## | 100% 
chardet-4.0.0        | 198 KB    | ########## | 100% 
py-lief-0.10.1       | 1.3 MB    | ########## | 100% 
markupsafe-2.0.1     | 22 KB     | ########## | 100% 
zlib-1.2.11          | 120 KB    | ########## | 100% 
wheel-0.36.2         | 31 KB     | ########## | 100% 
conda-4.10.1         | 3.1 MB    | ########## | 100% 
libffi-3.3           | 54 KB     | ########## | 100% 
yaml-0.2.5           | 87 KB     | ########## | 100% 
libarchive-3.4.2     | 1.6 MB    | ########## | 100% 
ca-certificates-2021 | 120 KB    | ########## | 100% 
conda-package-handli | 967 KB    | ########## | 100% 
filelock-3.0.12      | 10 KB     | ########## | 100% 
requests-2.25.1      | 51 KB     | ########## | 100% 
ncurses-6.2          | 1.1 MB    | ########## | 100% 
pytz-2021.1          | 244 KB    | ########## | 100% 
pycosat-0.6.3        | 108 KB    | ########## | 100% 
psutil-5.8.0         | 342 KB    | ########## | 100% 
sqlite-3.35.4        | 1.4 MB    | ########## | 100% 
zstd-1.4.9           | 809 KB    | ########## | 100% 
jinja2-3.0.0         | 99 KB     | ########## | 100% 
brotlipy-0.7.0       | 349 KB    | ########## | 100% 
ripgrep-12.1.1       | 1.5 MB    | ########## | 100% 
_libgcc_mutex-0.1    | 3 KB      | ########## | 100% 
six-1.15.0           | 13 KB     | ########## | 100% 
soupsieve-2.2.1      | 30 KB     | ########## | 100% 
pyopenssl-20.0.1     | 48 KB     | ########## | 100% 

Downloading and Extracting Packages

UnicodeDecodeError('ascii','/info/test/tests/data/\xed\x94\x84\xeb\xa1\x9c\xea\xb7\xb8\xeb\x9e\xa8.zip.json',22,23,'ordinal not in range(128)')


The command '/bin/sh -c conda install conda-build' returned a non-zero code: 1

解决方法

康达太老了

我用 continuumio/miniconda2:4.5.11 Docker 镜像复制了这个错误:

$ docker run --rm -it continuumio/miniconda2:4.5.11 bash
(base) root@a285050719ad:/# conda install -y conda-build

# ... similar output as OP ...

UnicodeDecodeError('ascii','/info/test/tests/data/\xed\x94\x84\xeb\xa1\x9c\xea\xb7\xb8\xeb\x9e\xa8.zip.json',22,23,'ordinal not in range(128)')

此外,尝试升级 conda 软件包失败并提供一些额外建议:

(base) root@a285050719ad:/# conda update conda
Solving environment: done

EncodingError: A unicode encoding or decoding error has occurred.
Python 2 is the interpreter under which conda is running in your base environment.
Replacing your base environment with one having Python 3 may help resolve this issue.
If you still have a need for Python 2 environments,consider using 'conda create'
and 'conda activate'.  For example:

    $ conda create -n py2 python=2
    $ conda activate py2

Error details: UnicodeDecodeError('ascii','ordinal not in range(128)')

也就是说,您真的不应该使用这些旧的 Miniconda2 映像,因为 conda 不再与 Anaconda Cloud 存储库兼容。

使用较新的 Miniconda 安装程序

一个干净的解决方案是安装更新的 Miniconda(或 Miniforge 或 Mambaforge)。最新版本的基础都包含 Python 3。如果由于某种原因必须在 base 中安装 Python 2,这意味着您不能拥有最新的 conda 或最新的 conda-build,那么似乎 {{3} }.

如果可能,使用最新版本,就像在 Python 3 中一样。如果需要,可以随时创建 Python 2 环境 - 最好不要在基础 .建议的解决方案:

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
...

此外,请考虑是否可以更简单地从预装 Conda 的现有 Docker 映像开始。

就地更新 Conda(不推荐)

脏版本仍会使用相同的 4.5.11 安装程序,但会立即升级。在 Docker 映像中,我可以将其升级到 4.8 并保留 Python 2.7,然后 conda-build 将安装在 3.18.11(截至 2021 年 5 月的当前版本为 3.21.4)。

这可以类似地在 Dockerfile 中使用类似的东西来完成

RUN conda install -y python=2.7 conda=4.8 && \
    conda clean -qafy && \
    conda install -y conda-build && \
    conda clean -qafy

注意:我需要第一次清理才能安装 conda-build

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...