我正在尝试使用官方centos python 2.7图片作为基础构建一个python映像:
当我通过base运行基本映像时,当docker试图从我的dockerfile构建它时,我得到了一个不同的python版本。
示例:
docker system prune # clean slate
docker pull centos/python-27-centos7:latest
docker run -it centos/python-27-centos7:latest /bin/bash
which python
> /opt/app-root/bin/python
python --version
> Python 2.7.16
exit所以..。在基本映像上打开bash,我就安装了python 2.7.16。
app.dockerfile含量
FROM centos/python-27-centos7:latest
RUN which python
RUN python --version
RUN pip install -U pip当我构建dockerfile时:
docker build --no-cache -f app.dockerfile .我得到了这个输出:
Sending build context to Docker daemon 14.34kB
Step 1/7 : FROM centos/python-27-centos7:2.7
---> 55ede294318e
Step 2/7 : RUN which python
---> Running in 2c1c217dc7a2
/opt/app-root/bin/python
Removing intermediate container 2c1c217dc7a2
---> 7f3692a71370
Step 3/7 : RUN python --version
---> Running in 12cfab19a44d
Python 2.7.5
Removing intermediate container 12cfab19a44d
---> 7d354cadd2af
Step 4/7 : RUN pip install -U pip
---> Running in 4d58f3999602
Traceback (most recent call last):
File "/opt/app-root/bin/pip", line 7, in <module>
from pip import main
File "/opt/app-root/lib/python2.7/site-packages/pip/__init__.py", line 4, in <module>
import logging
File "/opt/rh/python27/root/usr/lib64/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/opt/rh/python27/root/usr/lib64/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
The command '/bin/sh -c pip install -U pip' returned a non-zero code: 1这张图片现在显示python --在完全相同的路径上--是2.7.5。当我进入pip install命令时,它会失败,因为2.7.5中有一个bug,但是2.7.16已经解决了。
为什么我会看到这种不同?在映像上运行bash和在映像上运行构建步骤有什么不同?
发布于 2020-01-23 15:12:26
请看我上面的评论--似乎我使用了一种与我想象中的不同类型的图像。
https://stackoverflow.com/questions/59069491
复制相似问题