我正在使用Docker构建映像,
FROM python:3.6.5-alpine
WORKDIR /app
ADD . /app
RUN pip3 install -r requirements.txt
EXPOSE 5000
CMD ["python", "main.py"] # I've got set alias on Python == Python 3.6
requirements.txt:
alembic==1.0.9
cffi==1.12.3
bcrypt==3.1.6
blinker==1.4
Click==7.0
Faker==1.0.5
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-Login==0.4.1
Flask-Mail==0.9.1
Flask-Migrate==2.4.0
Flask-Moment==0.7.0
Flask-Script==2.0.6
Flask-SQLAlchemy==2.3.2
Flask-Testing==0.7.1
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
PyMySQL==0.9.3
SQLAlchemy==1.3.3
text-unidecode==1.2
Werkzeug==0.15.2
WTForms==2.2.1
但是,在构建时:
Step 1/6 : FROM python:3.6.5-alpine
---> 5be6d36f77ee
Step 2/6 : WORKDIR /app
---> Using cache
---> f9e7cc24d767
Step 3/6 : ADD . /app
---> 7d9d5bdcf5d6
Step 4/6 : RUN pip3 install -r requirements.txt
---> Running in b455df1a48e2
Collecting alembic==1.0.9 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/fc/42/8729e2491fa9b8eae160d1cbb429f61712bfc2d779816488c25cfdabf7b8/alembic-1.0.9.tar.gz (1.0MB)
Collecting bcrypt==3.1.6 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/ce/3a/3d540b9f5ee8d92ce757eebacf167b9deedb8e30aedec69a2a072b2399bb/bcrypt-3.1.6.tar.gz (42kB)
Could not find a version that satisfies the requirement cffi>=1.1 (from versions: )
No matching distribution found for cffi>=1.1
You are using pip version 10.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1
我的需求文件根本不包含cffi软件包,但是它试图将其拉出并失败。最初,我认为这可能是由于缓存造成的,所以我删除了所有容器和图像并从头开始构建它,但仍然遇到相同的错误。如您所见,出于某些神秘的原因,它也使用pip代替了pip3。
但是我要问的问题是,如果不在需求文件中,为什么为什么要拉包装?
答案 0 :(得分:0)
如果需要,Pip将安装依赖项。例如,如果我运行pip install packageA
,但packageA取决于packageB和packageC,则pip将安装全部3个(或至少尝试安装)。
这就是为什么您看到这种行为的原因。
pip3也不将自身称为pip3,因此,表示pip已过时的消息并不表示它正在运行python2版本的pip。仍然应该是pip3。