在 dockerfile 中运行 conda update 时出现问题
我正在尝试使用一些 conda 环境创建一个 docker 容器。当我以交互模式运行容器时,运行
conda update --all
conda env create -f env.yml
没有任何问题。但是,每当我尝试使用 Docker 文件执行这些命令时,我都会收到
/bin/sh: 1: conda: command not foud
如下所示的 Docker 文件:
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 编辑为以下内容:
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
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
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 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
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"
with the following error
/bin/bash: conda: command not found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Dockerfile 中执行 anaconda 之前,您必须在构建时使用
ENV
变量将 anaconda 添加到PATH
中。更新 .bashrc 中的 PATH 将使在使用 docker run 运行时可以在容器内调用 conda,但不能在 .bashrc 中的其他 RUN 语句中调用 conda泊坞窗文件。
You have to add anaconda to the
PATH
during build time with theENV
variable before executing anaconda inside the Dockerfile.Updating
PATH
in .bashrc will make it possible to call conda inside the container when run withdocker run
, but not in otherRUN
statements in the docker file.