【问题标题】:--extra-index-url is not working in docker file--extra-index-url 在 docker 文件中不起作用
【发布时间】:2021-09-22 11:27:12
【问题描述】:

我已经使用以下 docker-compose.yml 设置了本地 pypiserver,当我直接使用它时它正在工作

pip install -r requirements.txt --extra-index-url http://127.0.0.1:8082

但是,当我尝试在 Dockerfile 中使用相同的命令时,它不起作用。文件我创建了以下文件:

Dockerfile:

FROM python:3
ENV PYTHONUNBUFFERED=1
ARG PIP_EXTRA_INDEX_URL
WORKDIR /code
COPY requirements.txt /code/
RUN echo "${PIP_EXTRA_INDEX_URL}"
RUN pip install -r requirements.txt $PIP_EXTRA_INDEX_URL
COPY . /code/

docker-compose.yml

version: "3.9"

services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    build:
      context: .
      args:
        - PIP_EXTRA_INDEX_URL=http://127.0.0.1:8082/simple/
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8800:8000"
    depends_on:
      - db

当我尝试运行docker-compose up 我收到以下错误:

Looking in indexes: https://pypi.org/simple, http://127.0.0.1:8082/simple/
Collecting http://127.0.0.1:8082/simple/
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f7407596df0>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f7407596b20>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f74089dcf70>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f74089dca60>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f74089dcdf0>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/
ERROR: Could not install packages due to an OSError: HTTPConnectionPool(host='127.0.0.1', port=8082): Max retries exceeded with url: /simple/ (Caused by NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f74089dcac0>: Failed to establish a new connection: [Errno 111] Connection refused'))

ERROR: Service 'web' failed to build : The command '/bin/sh -c pip install -r requirements.txt $PIP_EXTRA_INDEX_URL' returned a non-zero code: 1

此代码中是否缺少任何配置?

【问题讨论】:

  • pypi 服务器与 docker 一起配置。

标签: python python-3.x docker docker-compose pypiserver


【解决方案1】:

127.0.0.1 将解析到容器内的容器本身。您必须指定从容器中看到的主机的 IP 地址。

参见例如How to get the IP address of the docker host from inside a docker container了解如何获取此信息。

【讨论】:

  • 对不起@tripleee,我忘了提到我已经用docker配置了本地pypiserver。更改IP地址后仍然报同样的错误。
  • 怎么改的?在哪里配置?最简单的解释是您仍然没有设法找出正确的 IP 地址。
  • tripleee,我在 ubuntu virtualbox 中运行这些项目。我已经使用以下过程来获取 IP 地址。help.ubuntu.com/stable/ubuntu-help/net-findip.html.en。我猜ip地址是正确的。
  • 不,该地址不适用于本地 Docker 容器。您必须查询 Docker 才能找到 Docker 主机的 IP 地址。我用链接更新了答案。
猜你喜欢
  • 2021-07-19
  • 1970-01-01
  • 2013-04-29
  • 2019-05-27
  • 2013-10-19
  • 1970-01-01
  • 2010-11-20
  • 1970-01-01
相关资源
最近更新 更多