Activate conda environment in docker(在 docker 中激活 conda 环境)
问题描述
我需要在 docker 中激活环境并在此环境中运行命令.我创建了环境,然后我尝试激活这个环境并以这种方式运行命令:
I need to activate environment in docker and run a command in this environment. I create the environment, but then I try to activate this environment and run the command in this way:
CMD [ "source activate mro_env && ipython kernel install --user --name=mro_env" ]
但是当我运行 docker 时出现错误:
but when I ran docker I get an error:
[FATAL tini (8)] exec source activate mro_env && ipython kernel install
--user --name=mro_env failed: No such file or directory
这是整个 Dockerfile:
This is the whole Dockerfile:
FROM continuumio/miniconda3
ADD /src/mro_env.yml /src/mro_env.yml
RUN conda env create -f /src/mro_env.yml
# Pull the environment name out of the mro_env.yml
RUN echo "source activate $(head -1 /src/mro_env.yml | cut -d' ' -f2)" > ~/.bashrc
ENV PATH /opt/conda/envs/$(head -1 /src/mro_env.yml | cut -d' ' -f2)/bin:$PATH
CMD [ "source activate mro_env && ipython kernel install --user --name=mro_env" ]
推荐答案
关注了这个教程 并且它起作用了.示例 Dockerfile:
Followed this tutorial and it worked. Example Dockerfile:
FROM continuumio/miniconda
WORKDIR /usr/src/app
COPY ./ ./
RUN conda env create -f environment.yml
# Make RUN commands use the new environment:
SHELL ["conda", "run", "-n", "myenv", "/bin/bash", "-c"]
EXPOSE 5003
# The code to run when container is started:
ENTRYPOINT ["conda", "run", "-n", "myenv", "python3", "src/server.py"]
更新:
您可以使用conda run --no-capture-output";如果您使用 4.9 版本的 conda,则不缓冲 IO.更新 Dockerfile:
You can use "conda run --no-capture-output" to not buffer IO if you use the 4.9 version of conda. Updated Dockerfile:
FROM continuumio/miniconda
WORKDIR /usr/src/app
COPY ./ ./
RUN conda env create -f environment.yml
# Make RUN commands use the new environment:
SHELL ["conda", "run", "--no-capture-output", "-n", "myenv", "/bin/bash", "-c"]
EXPOSE 5003
# The code to run when container is started:
ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "myenv", "python3", "src/server.py"]
这篇关于在 docker 中激活 conda 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 docker 中激活 conda 环境
基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
