美文网首页
Dockerfile 安装python

Dockerfile 安装python

作者: 一个摸鱼AI喵 | 来源:发表于2021-09-24 09:45 被阅读0次

    方式一:
    按安装包进行安装
    下载python:Download Python | Python.org
    卸载centos自带python2.7

    RUN rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
    RUN whereis python |xargs rm -frv
    

    vim Dockerfile

    RUN yum update && yum install -y sudo
    RUN set -ex \
     && yum -y install zlib-devel bzip2-devel libffi-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
     && yum clean all \
     && mkdir /usr/local/python3 
    
    COPY Python-3.6.9.tar.xz  /usr/local/python3/ 
    
    RUN set -ex \
     && cd /usr/local/python3 \
     && tar -xvJf  Python-3.6.9.tar.xz \
     && cd Python-3.6.9 \
     && ./configure prefix=/usr/local/python3 \
     && make && make install \
     && ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python \
     && ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip 
    
    RUN set -ex \
     && cd /usr/local/python \
     && python -V
    
    RUN pip install pymysql</pre>   #自己选择安装,
    

    如果是ubuntu,apt-get 部分修改

    RUN apt-get  update && apt-get install -y sudo
    RUN set -ex \
        && apt-get -y install zlib bzip2  openssl ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget mesa-libGL.x86_64 lzma xz-devel python-backports-lzma\
        vim curl git \
        && apt clean all \
        && mkdir /usr/local/python3 
    

    方式二:

    RUN apt-get update && \
     DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
     fakeroot \
     ca-certificates \
     dpkg-dev \
     g++ \
     cmake \
     python3-dev \
     openjdk-8-jdk-headless \
     libglib2.0-dev \
     libgl1-mesa-dev \
     libxrender1 \
     libgl1-mesa-glx \
     libxext-dev \
     curl vim wget git \
     && rm -rf /var/lib/apt/lists/* \
     && cd /tmp \
     && curl -O https://bootstrap.pypa.io/get-pip.py \
     && python3 get-pip.py
    
    RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
    RUN update-alternatives --install /usr/local/bin/pip pip /usr/local/bin/pip3 1
    

    此方法版本未知

    方法三:

    到hub.docker.com 查找python具体的版本进行安装

    docker pull python:3.6.9
    
    FROM python:3.6.9
    

    相关文章

      网友评论

          本文标题:Dockerfile 安装python

          本文链接:https://www.haomeiwen.com/subject/pgtxnltx.html