gpt4 book ai didi

python - 在docker中激活conda环境

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:19 25 4
gpt4 key购买 nike

我需要在 docker 中激活环境并在此环境中运行命令。我创建了环境,但随后我尝试激活这个环境并以这种方式运行命令:

CMD [ "source activate mro_env && ipython kernel install --user --name=mro_env" ]

但是当我运行 docker 时出现错误:

[FATAL tini (8)] exec source activate mro_env && ipython kernel install 
--user --name=mro_env failed: No such file or directory

这是整个 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" ]

最佳答案

关注此 tutorial它奏效了。示例 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"]

更新:

如果您使用 4.9 版本的 conda,您可以使用“conda run --no-capture-output”来不缓冲 IO。更新的 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"]

关于python - 在docker中激活conda环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55123637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com