软件包未使用pip安装在Docker容器内

时间:2020-04-13 15:59:02

标签: python docker docker-compose

我对docker-compose面临的一个奇怪问题感到困惑。对于require.txt文件中的某些软件包,点安装失败。

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

我尝试了很多可能的选择,但是没有用。一些例子是:

  1. 在容器内运行点升级。
  2. 根据线程here在docker中更新DNS。

3 个答案:

答案 0 :(得分:0)

@ WilliamD.Irons已经指出here apturl是一个包,您可以使用:

RUN apt install apturl
RUN pip3 install -r requirements.txt

并从您的apturl中删除requirements.txt

答案 1 :(得分:0)

apturl seems to be客户端Ubuntu程序,用于添加对网页中<a href="apt:package">click</a>之类的链接的支持:

apturl是一个图形小型程序,用于从用户拥有的存储库中安装软件包。自7.10版起,它已预装在Ubuntu上,并且Firefox和Pidgin程序都对此提供支持。

此外,还有other suggestions对此支持在Ubuntu之外不存在。由于官方python:3.7.5图片是基于Debian GNU/Linux的,因此无论如何都无法使用。

我想问为什么这需要在Flask应用程序的需求中,因为您应该只能够编写自己的python函数以在应用程序内生成兼容的链接。从受支持的客户端(根据上述方法,在装有Firefox的任何Ubuntu盒子)中访问这些链接的任何人都应该能够成功处理这些链接。

答案 2 :(得分:0)

如果使用基本容器不是问题,请尝试使用 Ubuntu 环境并安装 python。 apturl 由 ubuntu 提供,特别是因为它使用 apt

# Use the ubuntu
FROM ubuntu:lts


# Set the working directory to /app
WORKDIR /app

# install python and pip, and delete cache
RUN apt update && apt install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*

# 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"]