本文介紹了在 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 環境的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!