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'
更新conda
或Dockerfile
使用miniconda3:latest
此問題有 3 種可能的解決方案:
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?&&?\
使用最新的官方
Dockerfile
版本。conda
使用前更新容器內部:
(base)?root@61cafd17d954:/#?conda?update?conda
添加回答
舉報