2

I have setup local pypiserver using following docker-compose.yml and it is working when i use it directly like

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

However, When I try to use same command in Dockerfile, it is not working. Files I have created following files:

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

When I try to run docker-compose up I am getting following errors:

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

Is any configuration missing in this code?

1 Answers1

1

127.0.0.1 will resolve to the container itself inside the container. You have to specify the IP address of the host as seen from the container.

See e.g. How to get the IP address of the docker host from inside a docker container for how to obtain this information.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Sorry @tripleee, I forgot to mentioned that I have configured local pypiserver with docker. After changing IP address it still gives same error. – Mohanlal Prajapati Jul 13 '21 at 12:29
  • Changed how? Configured where? The simplest explanation is that you didn't manage to figure out the correct IP address still. – tripleee Jul 13 '21 at 12:32
  • tripleee, I am running these projects in ubuntu virtualbox. I have used following process to get IP address.https://help.ubuntu.com/stable/ubuntu-help/net-findip.html.en . I guess ip address is correct. – Mohanlal Prajapati Jul 13 '21 at 12:35
  • 1
    No, that address won't work for a local Docker container. You'll have to query Docker to find the IP address of your Docker host. I updated the answer with a link. – tripleee Jul 13 '21 at 12:37