亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Docker 中沒有名為 conda 的模塊

Docker 中沒有名為 conda 的模塊

一只萌萌小番薯 2023-09-05 20:50:11
我正在嘗試創建一個安裝了 miniconda3 的 docker 映像。我不想直接使用docker hub 中提供的基礎映像,而是想從頭開始創建自己的 Dockerfile 并將 Continumio/miniconda3 映像的 Dockerfile 的命令放在那里,這些命令是:FROM debian:latest#  $ docker build . -t continuumio/miniconda3:latest -t continuumio/miniconda3:4.5.11#  $ docker run --rm -it continuumio/miniconda3:latest /bin/bash#  $ docker push continuumio/miniconda3:latest#  $ docker push continuumio/miniconda3:4.5.11ENV.UTF-8 LC_ALL=C.UTF-8ENV PATH /opt/conda/bin:$PATHRUN apt-get update --fix-missing && \    apt-get install -y wget bzip2 ca-certificates curl git && \    apt-get clean && \    rm -rf /var/lib/apt/lists/*RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \    /bin/bash ~/miniconda.sh -b -p /opt/conda && \    rm ~/miniconda.sh && \    /opt/conda/bin/conda clean -tipsy && \    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \    echo "conda activate base" >> ~/.bashrcENV TINI_VERSION v0.16.1ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tiniRUN chmod +x /usr/bin/tiniENTRYPOINT [ "/usr/bin/tini", "--" ]CMD [ "/bin/bash" ]構建和運行容器效果很好。conda info作為參考,以下是容器中的輸出:(base) root@def48bd1ed5d:/# conda info     active environment : base    active env location : /opt/conda            shell level : 1       user config file : /root/.condarc populated config files :           conda version : 4.5.11    conda-build version : not installed         python version : 3.7.0.final.0
查看完整描述

1 回答

?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

miniconda3Dockerfile 內的安裝行中指定的版本不是最新版本

您用于構建本地映像的Dockerfile將安裝miniconda3-4.5.11不是最新版本。你可以在這里找到它:


...

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \

? ? /bin/bash ~/miniconda.sh -b -p /opt/conda &&

...

也以這種方式docker:


$ docker build --tag miniconda3:test .

$ docker docker run -i -t miniconda3:test /bin/bash

$ docker history --no-trunc miniconda3:test | grep Miniconda3


/bin/sh -c wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && ...

好吧,現在我們看一下官方continuumio/miniconda3:


$ docker run -i -t continuumio/miniconda3 /bin/bash

進而:


$ docker history --no-trunc continuumio/miniconda3 | grep Miniconda3


/bin/sh -c wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && ...

正如您所看到的,continuumio/miniconda3DockerHub 中的映像安裝的是最新版本miniconda3 4.8.2,而不是4.5.11版本。因此,從中構建的本地映像Dockerfile將生成帶有miniconda3:4.5.11.


python版本變更中斷conda

現在,讓我們找出conda失敗的原因。首先構建并運行:


$ docker build --tag miniconda3:test .

$ docker docker run -i -t miniconda3:test /bin/bash

獲取一些信息:


(base) root@61cafd17d954:/# conda info


? ? ?active environment : base

? ? active env location : /opt/conda

? ? ? ? ? ? shell level : 1

? ? ? ?user config file : /root/.condarc

?populated config files :?

? ? ? ? ? conda version : 4.5.11

? ? conda-build version : not installed

? ? ? ? ?python version : 3.7.0.final.0

? ? ? ?base environment : /opt/conda? (writable)

? ? ? ? ? ?channel URLs : https://repo.anaconda.com/pkgs/main/linux-64

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/main/noarch

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/free/linux-64

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/free/noarch

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/r/linux-64

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/r/noarch

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/pro/linux-64

? ? ? ? ? ? ? ? ? ? ? ? ? https://repo.anaconda.com/pkgs/pro/noarch

? ? ? ? ? package cache : /opt/conda/pkgs

? ? ? ? ? ? ? ? ? ? ? ? ? /root/.conda/pkgs

? ? ? ?envs directories : /opt/conda/envs

? ? ? ? ? ? ? ? ? ? ? ? ? /root/.conda/envs

? ? ? ? ? ? ? ?platform : linux-64

? ? ? ? ? ? ?user-agent : conda/4.5.11 requests/2.19.1 CPython/3.7.0 Linux/5.4.0-48-generic debian/10 glibc/2.28

? ? ? ? ? ? ? ? UID:GID : 0:0

? ? ? ? ? ? ?netrc file : None

? ? ? ? ? ?offline mode : False

好吧,我們conda:4.5.11有python:3.7.0。


現在,我們要安裝jupyter,例如:


(base) root@61cafd17d954:/# conda install jupyter

您可能會注意到,此安裝將更新python:


The following packages will be UPDATED:


...

? ? python:? ? ? ? ? ? ?3.7.0-hc3d631a_0? ? ? ? --> 3.8.5-h7579374_1? ? ? ?

...

如果繼續,這將更新python并會中斷conda:


...

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

Traceback (most recent call last):

? File "/opt/conda/bin/conda", line 7, in <module>

? ? from conda.cli import main

ModuleNotFoundError: No module named 'conda'

更新condaDockerfile使用miniconda3:latest

此問題有 3 種可能的解決方案:

  1. Dockerfile通過替換此行來編輯您的:

RUN?wget?--quiet?https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh?-O?~/miniconda.sh?&&?\

RUN?wget?--quiet?https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh?-O?~/miniconda.sh?&&?\
  1. 使用最新的官方Dockerfile版本。

  2. conda使用前更新容器內部:

(base)?root@61cafd17d954:/#?conda?update?conda


查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號