久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

構建期間在 Dockerfile 中激活和切換 Anaconda 環境

Activate and switch Anaconda environment in Dockerfile during build(構建期間在 Dockerfile 中激活和切換 Anaconda 環境)
本文介紹了構建期間在 Dockerfile 中激活和切換 Anaconda 環境的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經嘗試了幾個小時,但無法弄清楚如何在構建過程中在 Dockerfile 中激活和切換 anaconda 環境

I've been trying for hours and can't figure out how to activate and switch anaconda environments in a Dockerfile during the build process

這是初始代碼:

FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04

# Set user
ENV SETUSER myuser

RUN useradd -m $SETUSER
USER $SETUSER
WORKDIR /home/$SETUSER

# Install Anaconda
RUN wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
RUN bash Anaconda3-2019.03-Linux-x86_64.sh -b
RUN rm Anaconda3-2019.03-Linux-x86_64.sh

# Set path to conda
ENV CONDA_ENV_NAME mynewenv
RUN /home/$SETUSER/anaconda3/condabin/conda create -q --name $CONDA_ENV_NAME python=3.6 && 
    /home/$SETUSER/anaconda3/condabin/conda clean --yes --all
RUN /home/$SETUSER/anaconda3/condabin/conda activate base #Just for testing anaconda environment

一開始Docker中的anaconda會抱怨shell設置不正確,所以在conda create命令后我添加了:

At first, anaconda in Docker will complain that the shell is not setup properly, so after the conda create command I added:

RUN /home/$SETUSER/anaconda3/condabin/conda init bash
RUN /bin/bash -c "source /home/$SETUSER/.bashrc"
RUN /home/$SETUSER/anaconda3/condabin/conda activate base

在構建 docker 鏡像后運行 3 個命令有效(即在調用 docker run container-name 后交互運行),但由于某種原因,它在 構建 容器時不起作用.我發現 $PATH 變量在構建過程中沒有被更新,所以在構建時和構建后比較我的 $PATH.

Running the 3 commands after building the docker image works (i.e. running interactively after calling docker run container-name), but for some reason it does not work when building the container. I figured out that the $PATH variable was not being updated during the build, so comparing my $PATH when building and after building.

ENV PATH /home/$SETUSER/anaconda3/envs/$CONDA_ENV_NAME/bin:$PATH
ENV PATH /home/$SETUSER/anaconda3/condabin:$PATH
ENV PATH /home/$SETUSER/anaconda3/bin:$PATH
RUN conda init bash
RUN /bin/bash -c "source /home/$SETUSER/.bashrc"
RUN conda activate base

現在,構建時的 Docker $PATH 和構建后運行容器時交互修改時的 $PATH 是相同的,但我仍然收到 shell 未正確設置錯誤.

Now, the Docker $PATH when building and the $PATH when modified interactively when running the container after-building is the same, but I'm still getting the shell not properly setup error.

CommandNotFoundError:您的 shell 未正確配置為使用conda activate".要初始化你的 shell,運行$ 康達初始化目前支持的 shell 有:- 重擊- 魚-tcsh- xonsh-zsh- 電源外殼有關更多信息和選項,請參閱conda init --help".重要提示:運行conda init"后,您可能需要關閉并重新啟動 shell.

為什么這不起作用???

Why is this not working???

我已經看到可能有使用 miniconda docker 模板的解決方法,但我不能使用它.Docker搭建過程中如何創建和切換anaconda環境?謝謝!

I've seen that there may be workaround using a miniconda docker template, but I cannot use that. How do I create and switch anaconda environment during the Docker building process? Thanks!

推薦答案

你的 Dockerfile 中有太多的 RUN 命令.不僅僅是每個 RUN 在圖像中創建一個新層.也是每個 RUN 命令都會啟動一個新的 shell,而 conda activate 只適用于當前的 shell.

You've got way too many RUN commands in your Dockerfile. It's not just that each RUN creates a new layer in the image. It's also that each RUN command starts a new shell, and conda activate applies only to the current shell.

您應該將操作的邏輯組組合成一個 RUN 命令.使用 && 組合命令,使用 換行以提高可讀性:

You should combine logical groups of actions into a single RUN command. Use && to combine commands, and to break lines for readability:

RUN conda activate <myenv> 
 && conda install <whatever> 
 && ...

請記住:在該 RUN 命令結束時,shell 將消失.因此,如果您想在之后對該 conda 環境執行其他操作,則必須再次運行 conda activate ,或者使用 -n <myenv> 放置一些東西進入一個環境而不先激活它.

Keep in mind: at the end of that RUN command, the shell will be gone. So if you want to do something else to that conda environment afterwards, you've got to run conda activate again, or else use -n <myenv> to put something into an environment without activating it first.

當你從鏡像啟動一個容器時,你還必須在容器內調用 conda activate.

When you start a container from the image, you will also have to call conda activate inside the container.

這篇關于構建期間在 Dockerfile 中激活和切換 Anaconda 環境的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 亚洲精品一区在线 | v亚洲 | 羞羞视频免费在线观看 | 干一干操一操 | 日韩精品成人一区二区三区视频 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 国产在线精品一区二区 | 国产韩国精品一区二区三区 | 久热国产精品视频 | 欧产日产国产精品v | 国产一区二区三区高清 | 日日夜夜影院 | 久久久精品一区二区三区四季av | 久久亚洲国产精品 | 日韩高清一区二区 | 久久er99热精品一区二区 | 亚洲美女一区 | 国产一区在线免费 | 国产精品不卡一区二区三区 | 五月激情六月婷婷 | 色网站在线 | 久久成人免费视频 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | av影音资源| 亚洲另类春色偷拍在线观看 | 欧美日韩精品 | 伊人电影院av | 欧美日韩亚洲一区二区 | 欧美一级片a | 欧美日韩精品在线一区 | 一级黄色毛片a | 日韩精品在线播放 | 中文字幕欧美日韩一区 | 久久成人免费视频 | 91视频中文 | 免费1区2区3区 | 最新av在线网址 | 久久久久久久久久性 | 偷偷操视频| 男女激情网 | 亚洲国产精品久久 |