我对 docker-compose 面临的一个奇怪问题感到困惑。对于requirements.txt 文件中的某些软件包,Pip 安装失败。
docker 版本
Client:
Version: 18.09.9
API version: 1.39
Go version: go1.13.4
Git commit: 1752eb3
Built: Sat Nov 16 01:05:26 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.9
API version: 1.39 (minimum version 1.12)
Go version: go1.13.4
Git commit: 9552f2b
Built: Sat Nov 16 01:07:48 2019
OS/Arch: linux/amd64
Experimental: false
我的docker-compose.yml
文件是:
version: "3.7"
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
expose:
- 8080
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
./flask目录中Dockerfile
的内容是:
# Use the Python3.7.5 image
FROM python:3.7.5
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install the dependencies
RUN pip3 install -r requirements.txt
# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
我的 requirements.txt
文件是(前几行):
appdirs==1.4.3
apturl==0.5.2
asn1crypto==0.24.0
bcrypt==3.1.6
blinker==1.4
但是,当我运行 docker-compose up
命令时,它无法安装 requirements.txt
文件中的第二个包。
Building flask
Step 1/6 : FROM python:3.7.5
---> fbf9f709ca9f
Step 2/6 : WORKDIR /app
---> Using cache
---> 39ab3ee34991
Step 3/6 : ADD . /app
---> Using cache
---> 8968809ff844
Step 4/6 : RUN python3 -m pip install --upgrade pip
---> Using cache
---> 15f717de5181
Step 5/6 : RUN pip3 install -r requirements.txt
---> Running in 7068f09498dc
Collecting appdirs==1.4.3
Downloading appdirs-1.4.3-py2.py3-none-any.whl (12 kB)
ERROR: Could not find a version that satisfies the requirement apturl==0.5.2 (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for apturl==0.5.2 (from -r requirements.txt (line 2))
ERROR: Service 'flask' failed to build: The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1
我尝试了很多可能的选择,但没有用。一些例子是:
- 在容器内运行 pip Upgrade。
- 按照线程 here 更新 docker 中的 DNS .
最佳答案
正如 @WilliamD.Irons 已经指出的 here apturl
是一个包,您可以使用:
RUN apt install apturl
RUN pip3 install -r requirements.txt
并从 requirements.txt
中删除 apturl
关于python - 使用 pip 未将软件包安装在 docker 容器内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61191757/