condas`source activate virtualenv`在Dockerfile中不起作用

编程入门 行业动态 更新时间:2024-10-09 04:16:12
本文介绍了condas`source activate virtualenv`在Dockerfile中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试基于公众我对docker还是很陌生,所以请更正我可能的误解). .docker/r/continuumio/anaconda3/"rel =" noreferrer> continuumio/anaconda3 容器.

I'm trying to setup a simple docker image (I'm quite new to docker, so please correct my possible misconceptions) based on the public continuumio/anaconda3 container.

Dockerfile:

FROM continuumio/anaconda3:latest # update conda and setup environment RUN conda update conda -y \ && conda env list \ && conda create -n testenv pip -y \ && source activate testenv \ && conda env list

docker build -t test .对此的建筑物和图像以错误结束:

Building and image from this by docker build -t test . ends with the error:

/bin/sh: 1: source: not found

在激活新的虚拟环境时.

when activating the new virtual environment.

按照此答案,我尝试过:

FROM continuumio/anaconda3:latest # update conda and setup environment RUN conda update conda -y \ && conda env list \ && conda create -y -n testenv pip \ && /bin/bash -c "source activate testenv" \ && conda env list

这似乎起初是有效的,因为它输出:prepending /opt/conda/envs/testenv/bin to PATH,但是conda env list以及echo $PATH都清楚地表明它没有:

This seems to work at first, as it outputs: prepending /opt/conda/envs/testenv/bin to PATH, but conda env list as well ass echo $PATH clearly show that it doesn't:

[...] # conda environments: # testenv /opt/conda/envs/testenv root * /opt/conda ---> 80a77e55a11f Removing intermediate container 33982c006f94 Step 3 : RUN echo $PATH ---> Running in a30bb3706731 /opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

泊坞窗文件作为MWE开箱即用. 我感谢任何想法.谢谢!

The docker files work out of the box as a MWE. I appreciate any ideas. Thanks!

推荐答案

我已经开发了一种改良的新方法,它比"conda", "run"语法更好.

I have developed a new, improved approach which better than the "conda", "run" syntax.

在此要点可用的dockerfile示例.它通过利用自定义入口点脚本在exec节的参数之前设置环境来工作.

Sample dockerfile available at this gist. It works by leveraging a custom entrypoint script to set up the environment before execing the arguments of the RUN stanza.

我以前的回答:

这是一种更现代的方法,由 Itamar Turner-Trauring 提供;非常感谢他们!

Here is a more modern approach, courtesy of Itamar Turner-Trauring; many thanks to them!

# Create the environment: COPY environment.yml . RUN conda env create -f environment.yml # Set the default docker build shell to run as the conda wrapped process SHELL ["conda", "run", "-n", "vigilant_detect", "/bin/bash", "-c"] # Set your entrypoint to use the conda environment as well ENTRYPOINT ["conda", "run", "-n", "myenv", "python", "run.py"]

修改ENV可能不是最好的方法,因为conda喜欢控制环境变量本身.此外,您的自定义conda env可能会激活其他脚本来进一步调节环境.

Modifying ENV may not be the best approach since conda likes to take control of environment variables itself. Additionally, your custom conda env may activate other scripts to further modulate the environment.

这利用了 conda运行,以将条目添加到环境的PATH并运行该环境可能包含的任何激活脚本".在启动新的bash shell之前.

This leverages conda run to "add entries to PATH for the environment and run any activation scripts that the environment may contain" before starting the new bash shell.

使用conda可能会令人沮丧,因为这两个工具都有效地希望垄断环境,并且从理论上讲,您永远不需要容器内的conda.但是截止日期和技术债务是一个问题,有时您只是必须完成它,有时conda是配置依赖项的最简单方法(在您看来,GDAL).

Using conda can be a frustrating experience, since both tools effectively want to monopolize the environment, and theoretically, you shouldn't ever need conda inside a container. But deadlines and technical debt being a thing, sometimes you just gotta get it done, and sometimes conda is the easiest way to provision dependencies (looking at you, GDAL).

更多推荐

condas`source activate virtualenv`在Dockerfile中不起作用

本文发布于:2023-11-25 11:52:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   source   condas   activate   Dockerfile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!