10

I've been trying to get django to run via uwsgi in a docker container.

I had django running in docker, with its built in web server, but now that I've modified the requirements.txt to include uwsgi, I keep getting the following error message:

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/uwsgi/

So it seems like the url docker is using for pip packages is /simple, but how did that change? When I first created the container django and psycopg got downloaded fine.

I tried specifying the full URL of the uwsgi package, but that didn't work either.

docker-compose.yaml:

version: '3'
services:
  db:
    image: postgres
  web:
    dns: 8.8.8.8
    build: .
    command: uwsgi --http :8000 --module destExp.wsgi
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

Dockerfile:

FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
CMD uwsgi --http :8000 --module destExp.wsgi
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90

1 Answers1

6

That error is due pip is unable to reach to the mirror host. Part /simple/uwsgi is being used as pip url path.

DNS line in Compose is ignored for v3 specification if you are deploying to Swarm, as stated in the doc. Here is a workaround to make pip use different DNS momentarily, simply update your pip line in Dockerfile to following:

RUN echo nameserver 8.8.8.8 > /etc/resolv.conf && pip install -r requirements.txt

Hope that helps. As a permanent solution, you should investigate how to make your orchestration use the custom DNS or troubleshoot the current DNS from the container for your case.

hurturk
  • 5,214
  • 24
  • 41