构建Docker镜像时出现Conda未找到的问题

6
我已经制作了一个用于 Plink 和 Peddy 的 Docker 容器,但每当我尝试构建容器时,都会出现以下错误:
Executing transaction: ...working... WARNING conda.core.envs_manager:register_env(46): Unable to register environment. Path not writable or missing.
  environment location: /root/identity_check/anaconda
  registry file: /root/.conda/environments.txt
done
installation finished.
Removing intermediate container cdf60f5bf1a5
 ---> be254b7571be
Step 7/10 : RUN conda update -y conda   && conda config --add channels bioconda         && conda install -y peddy
 ---> Running in aa2e91da28b4
/bin/sh: 1: conda: not found
The command '/bin/sh -c conda update -y conda   && conda config --add channels bioconda         && conda install -y peddy' returned a non-zero code: 127

Dockerfile:
FROM ubuntu:19.04

WORKDIR /identity_check

RUN apt-get update && \
    apt-get install -y \
        python-pip \
        tabix \
        wget \
        unzip 

RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/* \
    && sudo apt-get -y update \
    && sudo pip install --upgrade pip \
    && sudo pip install awscli --upgrade --user \
    && sudo pip install boto3 \
    && sudo pip install pyyaml \
    && sudo pip install sqlitedict


# Install PLINK
RUN wget http://s3.amazonaws.com/plink1-assets/plink_linux_x86_64_20190617.zip \
    && mv plink_linux_x86_64_20190617.zip /usr/local/bin/ \
    && unzip /usr/local/bin/plink_linux_x86_64_20190617.zip

# Install Peddy
RUN INSTALL_PATH=~/anaconda \
    && wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh \
    && bash Miniconda2-latest* -fbp $INSTALL_PATH \
    && PATH=$INSTALL_PATH/bin:$PATH

RUN conda update -y conda \
    && conda config --add channels bioconda \
    && conda install -y peddy

ENV PATH=$PATH:/identity_check/

ADD . /identity_check

CMD bash /identity_check/identity_setup.sh 

我尝试更改 INSTALL_PATH 看是否有所改变,甚至启动了虚拟机手动测试这些安装步骤,一切都正常。我不明白为什么找不到 conda。


1个回答

1
# Install Peddy
RUN INSTALL_PATH=~/anaconda \
    && wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh \
    && bash Miniconda2-latest* -fbp $INSTALL_PATH \
    && PATH=$INSTALL_PATH/bin:$PATH

上面的最后一部分更新了一个PATH变量,该变量仅存在于运行命令的shell中。在设置PATH变量后,该shell立即退出,并且用于执行RUN命令的临时容器也会退出。 RUN命令的结果是将文件系统更改汇集到正在创建的docker镜像的一个层中。任何环境变量更改、启动的后台进程或任何其他不属于容器文件系统的内容都将丢失。

相反,您将希望使用以下方式更新图像环境:

# Install Peddy
RUN INSTALL_PATH=~/anaconda \
    && wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh \
    && bash Miniconda2-latest* -fbp $INSTALL_PATH \
ENV PATH=/root/anaconda/bin:$PATH

如果软件允许的话,我会避免在 /root 主目录下安装,并选择在 /usr/local/bin 等其他位置进行安装,这样可以在将容器更改为以不同用户运行时仍然可用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接