0

Question

i can't install any package during building an image. pulling from docker hub is OK, but problems occurred when docker try to use network to build an image. for example, if i try to run:

$ docker build -t sample-image:latest .

... and the Dockerfile that used by above command has following line:

RUN pip install -r requirements.txt

... then i get next error:

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdbe102e278>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/sanic/

Could not find a version that satisfies the requirement sanic (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for sanic (from -r requirements.txt (line 1))

... the same error appear when ubuntu packages are updating


Info

docker and docker compose installed by official docker's documentation (without any changes).

Server Version: 17.03.1-ce
Storage Driver: aufs
Kernel Version: 4.8.0-45-generic
Operating System: Ubuntu 16.04.2 LTS
Architecture: x86_64
CPUs: 2
Total Memory: 3.763 GiB

requirements.txt:

sanic
asyncpg
asyncio
uvloop

Dockerfile:

FROM python:3.5-onbuild

WORKDIR /usr/src/app

# https://github.com/vishnubob/wait-for-it
CMD ["./run/wait-for-it.sh", "db:5432", "--", "python", "index.py"]

P.S.

i test more decisions and none helped yet. thanks for help everyone :)

Yurii Rabeshko
  • 591
  • 8
  • 17
  • 1
    Could this http://stackoverflow.com/questions/28668180/cant-install-pip-packages-inside-a-docker-container-with-ubuntu/35277904 be helpful? – shizhz Apr 06 '17 at 00:10
  • How are you defining the sanic dependency in your `requirements.txt`? The `/simple/sanic/` looks odd – Matt Apr 06 '17 at 05:30
  • [shizhz](http://stackoverflow.com/users/1000254/shizhz), unfortunately decision above doesn't helped me (behavior of image building doesn't change)... can you any other ideas? – Yurii Rabeshko Apr 06 '17 at 06:21
  • [Matt](http://stackoverflow.com/users/1318694/matt), requirements.txt so clear (look above). All this code works pretty cool at another computer with other hardware but the same software. It confuse me :( – Yurii Rabeshko Apr 06 '17 at 06:21
  • 1
    @YuriiRabeshko Try to edit `/etc/NetworkManager/NetworkManager.conf` and comment out the `dns=dnsmasq` part, restart the network and docker and try again – Salem Apr 06 '17 at 20:12
  • [Salem](http://stackoverflow.com/users/1205368/salem), you are crazy man ;) i was finding a solution for 2 weeks but decision of the problem was so easy to fix.. thank you veeeeeery much)) – Yurii Rabeshko Apr 08 '17 at 00:57

2 Answers2

1

thanks Salem! following decision helped me:

Try to edit /etc/NetworkManager/NetworkManager.conf and comment out the dns=dnsmasq part, restart the network and docker and try again

Yurii Rabeshko
  • 591
  • 8
  • 17
  • 1
    Running docker 1.11.2 on ubuntu-xenial in a VirtualBox VM. The other dns suggestions on http://stackoverflow.com/questions/28668180/cant-install-pip-packages-inside-a-docker-container-with-ubuntu/35277904 didn't help but this did. – bvanlew May 24 '17 at 11:12
0

If pip install succeeds when installing packages on host machine but not during docker build, then the solution that worked for me is to have the index-url from the host machine's /etc/pip.conf present in that of the docker image.

Example:

If the host machine's /etc/pip.conf contains:

  • index-url = https://example.com/blah/blah/blah

Then add the following line to the Dockerfile before installing any pip packages:

  • RUN echo '[global]\nindex-url = https://example.com/blah/blah/blah\ntrusted-host = https://example.com' > /etc/pip.conf
Ashish
  • 1
  • 3