python - 您的 shell 尚未正确配置为在 dockerfile 上使用 'conda activate'

标签 python docker anaconda

我正在使用 docker 制作 anaconda3 环境。

但是它显示如下错误。

我想这与一些 shell 问题有关..但我还不能修复。

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

我的 dockerfile 在这里。
FROM ubuntu:18.04

RUN apt-get -y update
RUN apt-get -y install emacs wget
RUN wget https://repo.continuum.io/archive/Anaconda3-2019.07-Linux-x86_64.sh
RUN /bin/bash Anaconda3-2019.07-Linux-x86_64.sh -b -p $HOME/anaconda3
RUN echo 'export PATH=/root/anaconda3/bin:$PATH' >> /root/.bashrc 

#RUN source /root/.bashrc
RUN . /root/.bashrc
RUN /root/anaconda3/bin/conda init bash
RUN /root/anaconda3/bin/conda create -n py37 python=3.7 anaconda
RUN /root/anaconda3/bin/conda activate py37

最佳答案

我相信您的问题可能是您正在采购 .bashrc在与依赖它的命令不同的行中。来自 Dockerfile documentation :

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.



这意味着您正在采购您的 .bashrc在一层(第一个 RUN 行),然后是 RUNconda 中的命令新品 层,对上一层中的环境一无所知。

尝试这样的事情:
RUN . /root/.bashrc && \
    /root/anaconda3/bin/conda init bash && \
    /root/anaconda3/bin/conda create -n py37 python=3.7 anaconda && \
    /root/anaconda3/bin/conda activate py37

通过在一行上运行它们,您是在单个层中运行它们。

关于python - 您的 shell 尚未正确配置为在 dockerfile 上使用 'conda activate',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60855061/

相关文章:

docker - 卡夫卡消费者无法连接

anaconda - Conda 不会更新包

linux - 是否可以将字符串发送到 docker 容器内的运行进程中?

perl - 如何修复 anaconda 中的 Perl 未安装 bioperl 的问题? `Bailing out the installation for BioPerl-1.007002.`

installation - Conda 包的离线安装顺序

python - Pandas:更高效的索引转储?

python - Pandas 如何设置日期作为索引,这是一个好主意吗?

python - 从 Python 列表中提取数字

python - 在大型 python 程序中保存状态而不将变量作为参数传递

docker - Traefik SSL 配置