提问者:小点点

使用Docker激活conda时CommandNotFoundError


我是Docker的新手,尝试通过激活Conda环境来构建Docker映像。 但我做不到。

这是我的DockerFile:

FROM continuumio/miniconda3

COPY . /app

WORKDIR /app

RUN conda env create -f environment.yml

SHELL ["conda", "run", "-n", "FM", "/bin/bash", "-c"]

RUN conda activate FM

ENTRYPOINT ["conda", "run", "-n", "FM", "python", "src/run.py"]

我的环境.yml文件:

name: FM
channels:
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - ca-certificates=2020.6.24=0
  - certifi=2020.6.20=py37_0
  - ld_impl_linux-64=2.33.1=h53a641e_7
  - libedit=3.1.20191231=h7b6447c_0
  - libffi=3.2.1=hd88cf55_4
  - libgcc-ng=9.1.0=hdf63c60_0
  - libstdcxx-ng=9.1.0=hdf63c60_0
  - ncurses=6.2=he6710b0_1
  - openssl=1.1.1g=h7b6447c_0
  - pip=20.1.1=py37_1
  - python=3.7.6=h0371630_2
  ...
  - pip:
    - click==7.1.2
    - cycler==0.10.0
    - decorator==4.4.2
    - flask==1.1.2
    - imageio==2.9.0
    - itsdangerous==1.1.0
    ...
prefix: /home/huytran/miniconda3/envs/FM

当我构建映像Docker build-t condatest.时,会出现以下错误:

...
Step 5/8 : SHELL ["conda", "run", "-n", "FM", "/bin/bash", "-c"]
 ---> Running in 962623c513cc
Removing intermediate container 962623c513cc
 ---> c5a91349830f
Step 6/8 : RUN conda activate FM
 ---> Running in 1f3d1cd0c50b

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'.

你们知道我错在哪里吗?


共1个答案

匿名用户

运行conda activate fm不执行任何操作,因为它只在特定的运行中激活。 它对以后的runentrypoint/cmd命令没有影响。

这也是不必要的,因为您正在入口点中使用condaRun,并使用shell来启用环境ala https://pythonspeed.com/articles/activate-conda-dockerfile/。

只要省略它,你就会没事的。