如何在 Dockerfile 中使用 miniconda 安装软件包?

mac*_*iek 22 python docker anaconda miniconda dockerfile

我有一个简单的 Dockerfile:

FROM ubuntu:18.04

RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

RUN wget \
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && mkdir /root/.conda \
    && bash Miniconda3-latest-Linux-x86_64.sh -b \
    && rm -f Miniconda3-latest-Linux-x86_64.sh \
    && echo PATH="/root/miniconda3/bin":$PATH >> .bashrc \
    && exec bash \
    && conda --version

RUN conda --version
Run Code Online (Sandbox Code Playgroud)

它不能被建造。在最后一步,我得到了/bin/sh: 1: conda: not found......
第一次出现conda --version没有引发错误,这让我想知道这是一个PATH问题吗?
我想RUN在这个 Dockerfile 中有另一个条目,我将在其中安装包conda install ...
最后我想要CMD ["bash", "test.py"]条目,以便在执行docker run此图像时它会自动运行一个简单的 python 脚本,该脚本导入所有使用 conda 安装的库。也许还有一个CMD ["bash", "test.sh"]脚本可以测试是否确实安装了 conda 和 python 解释器。

这是一个简化的例子,会有很多软件,所以我不想改变基本图像。

Lin*_*nPy 48

这将使用 ARG 和 ENV:

FROM ubuntu:18.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

RUN wget \
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && mkdir /root/.conda \
    && bash Miniconda3-latest-Linux-x86_64.sh -b \
    && rm -f Miniconda3-latest-Linux-x86_64.sh 
RUN conda --version
Run Code Online (Sandbox Code Playgroud)

  • 如果您收到“/bin/sh: conda: command not found”,是因为您没有将 miniconda 添加到您的 PATH 中。这就是为什么您必须设置代码片段顶部显示的环境变量。 (4认同)