在dockerfile中运行conda更新时出现问题 [英] Problems running conda update in a dockerfile
问题描述
我正在尝试使用一些conda环境创建一个docker容器.当我在运行
I am trying to create a docker container with some conda environments. When I run the container in interactive mode running
conda update --all
conda env create -f env.yml
运行没有问题.但是,每当我尝试使用Docker文件执行这些命令时,我都会收到
runs with no issues. However whenever I try to execute these commands with a Docker file I recieve
/bin/sh: 1: conda: command not foud
Docker文件如下所示:
Docker file is shown below:
FROM ubuntu:latest
RUN apt-get update && \
apt-get install unzip && \
mkdir /install && \
apt-get install nano
COPY Anaconda3-2018.12-Linux-x86_64.sh env.yml /install/
WORKDIR /install
RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
/bin/bash -c "source ~/.bashrc"
RUN conda update --all
RUN conda env create -f env.yml
因此似乎使用了sh而不是bash,所以我将Dockerfile编辑为以下内容:
So it appears that sh is being used instead of bash so I edited the Dockerfile to the following:
FROM ubuntu:latest
RUN apt-get update && \
apt-get install unzip && \
mkdir /install && \
apt-get install nano
COPY Anaconda3-2018.12-Linux-x86_64.sh env.yml /install/
WORKDIR /install
RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
/bin/bash -c "source ~/.bashrc"
RUN /bin/bash -c "conda update --all"
出现以下错误
/bin/bash: conda: command not found
推荐答案
在Dockerfile中执行anaconda之前,您必须在构建期间使用ENV
变量将anaconda添加到PATH.
You have to add anaconda to the PATH during build time with the ENV
variable before executing anaconda inside the Dockerfile.
RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
/bin/bash -c "source ~/.bashrc"
ENV PATH /root/anaconda3/bin:$PATH
RUN conda update --all
在.bashrc中更新PATH将使在使用docker run
运行时可以在容器内调用conda,但无法在docker文件中的其他RUN
语句中调用.
Updating PATH in .bashrc will make it possible to call conda inside the container, when run with docker run
, but not in other RUN
statements in the docker file.
这篇关于在dockerfile中运行conda更新时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!