Install pip in docker

前端 未结 4 1849
野的像风
野的像风 2020-12-09 01:01

I\'m not able to install pip in Docker.

Here\'s my Dockerfile:

FROM ubuntu:14.04

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y         


        
相关标签:
4条回答
  • 2020-12-09 01:27

    You might want to change the DNS settings of the Docker daemon. You can edit (or create) the configuration file at /etc/docker/daemon.json with the dns key, as

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

    In the example above, the first element of the list is the address of your DNS server. The second item is the Google’s DNS which can be used when the first one is not available.

    Before proceeding, save daemon.json and restart the docker service.

    sudo service docker restart
    

    Once fixed, retry to run the build command.

    0 讨论(0)
  • 2020-12-09 01:33

    Try this:

    1. Uncomment the following line in /etc/default/docker DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
    2. Restart the Docker service sudo service docker restart
    3. Delete any images which have cached the invalid DNS settings.
    4. Build again and the problem should be solved.

    From this question.

    0 讨论(0)
  • 2020-12-09 01:39

    While T. Arboreus's answer might fix the issues with resolving 'archive.ubuntu.com', I think the last error you're getting says that it doesn't know about the packages php5-mcrypt and python-pip. Nevertheless, the reduced Dockerfile of you with just these two packages worked for me (using Debian 8.4 and Docker 1.11.0), but I'm not quite sure if that could be the case because my host system is different than yours.

    FROM ubuntu:14.04
    
    # Install dependencies
    RUN apt-get update && apt-get install -y \
        php5-mcrypt \
        python-pip
    

    However, according to this answer you should think about installing the python3-pip package instead of the python-pip package when using Python 3.x.

    Furthermore, to make the php5-mcrypt package installation working, you might want to add the universe repository like it's shown right here. I had trouble with the add-apt-repository command missing in the Ubuntu Docker image so I installed the package software-properties-common at first to make the command available.

    Splitting up the statements and putting apt-get update and apt-get install into one RUN command is also recommended here.

    Oh and by the way, you actually don't need the -y flag at apt-get update because there is nothing that has to be confirmed automatically.

    Finally:

    FROM ubuntu:14.04
    
    # Install dependencies
    RUN apt-get update && apt-get install -y \
        software-properties-common
    RUN add-apt-repository universe
    RUN apt-get update && apt-get install -y \
        apache2 \
        curl \
        git \
        libapache2-mod-php5 \
        php5 \
        php5-mcrypt \
        php5-mysql \
        python3.4 \
        python3-pip
    

    Remark: The used versions (e.g. of Ubuntu) might be outdated in the future.

    0 讨论(0)
  • 2020-12-09 01:39

    An alternative is to use the Alpine Linux containers, e.g. python:2.7-alpine. They offer pip out of the box (and have a smaller footprint which leads to faster builds etc).

    0 讨论(0)
提交回复
热议问题