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

How to install packages with miniconda in 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

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

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

这将使用 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