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
添加回答
举报