Can't install pip packages inside a docker container with Ubuntu

前端 未结 16 2220
抹茶落季
抹茶落季 2020-11-30 19:07

I\'m following the fig guide to using docker with a python application, but when docker gets up to the command

RUN pip install -r requirements.txt

相关标签:
16条回答
  • 2020-11-30 19:41

    As a Docker newbie, I had a problem that manifested itself in this way when I was following the tutorial for Docker at:

    https://docs.docker.com/get-started/part2

    I'm using Docker 17.03.1-ce on a corporate LAN.

    I checked and double checked my DNS settings. I'd used various ways of configuring the DNS that I'd found in my searches across the Internet. Some caused errors on startup. The approach that I ultimately settled upon for configuring the DNS was the one in the Troubleshoot Linux section of the above link above where the DNS is configured via the daemon.json file in the /etc/docker directory.

    However, I still had this same issue. What finally solved the problem for me was the configuration of the proxy via the http_proxy and https_proxy environment variables. I had them specified in my Dockerfile, but I neglected to do so before the RUN pip command.

    Even though it appeared to be a DNS issue, moving these ENV commands ahead of the RUN command made the difference for me. In case that is helpful for anyone with this problem.

    0 讨论(0)
  • 2020-11-30 19:43

    For me, I was unable to install pip due to the docker's DNS not configured properly. I've tried the above steps, however, configuring docker DNS to Google DNS does not work for my laptop. Docker's DNS can be properly configured only if I set its DNS to my laptop's assigned IP.

    If you use Ubuntu, you can use the following steps to configure your docker's DNS:

    1. Find out your device's assigned IP. You can find this by either

      • Checking the inet addr of your ethernet or wlan in ifconfig
      • Choosing any address in nmcli dev show | grep 'DNS'
    2. Edit dns in /etc/docker/daemon.json (create this file if it doesn't exist previously)

      {
          "dns": ["your_ip_in_step_1"]
      }
      
    3. Restart docker: sudo service docker restart

    0 讨论(0)
  • 2020-11-30 19:43

    I do not know the reason, but the error means that pip is trying to resolve the /simple/blinker/ as a DNS hostname instead of the pypi.python.org part, which seems very odd since I cannot even come up with any URL for which urlparse could return such a string as a hostname part. I'd check if there is some problem with ~/.pip/pip.conf

    0 讨论(0)
  • 2020-11-30 19:48

    I had the same issue and it plagued me for a while and I tried a lot of solutions online but to no avail. However I finally resolved it as follows:

    Running:

    Ubuntu 16.04 
    docker Server 18.03.0-ce
    
    1. Discover the address of your DNS server.

      Discover the address of your DNS server by running the following command:

      $: nmcli dev show | grep 'IP4.DNS'
      IP4.DNS[1]:                192.168.210.2
      
    2. Update the Docker daemon

      Create a docker config file at /etc/docker/daemon.json. (if you don't already have one) and add the following content to the file:

      {
          "dns": ["192.168.210.2", "8.8.8.8"]
      }
      

      The first item of the array is your network's DNS server and the second is google's DNS server as a fallback when if your network's DNS is not available.

      Save the file and then restart the docker service

      $: sudo service docker restart
      
    0 讨论(0)
提交回复
热议问题