python3.6及anaconda基础镜像dockerfile(基于centos 操作系统)

python3.6

FROM centos:centos7.5.1804

RUN  yum -y install wget gcc make openssl-devel bzip2-devel \
     expat-devel gdbm-devel readline-devel sqlite-devel \
     mysql-devel gcc-devel python-devel xz-devel

RUN  mkdir -p /home/python \
     &&wget -P /home/python https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz \
     &&tar -zxvf /home/python/Python-3.6.5.tgz -C /home/python \
     &&cd /home/python/Python-3.6.5 \
     &&./configure --prefix=/usr/local/python  &&  make && make install \
     &&ln -s /usr/local/python/bin/python3 /usr/bin/python3 \
     &&ln -s /usr/local/python/bin/pip3 /usr/bin/pip3 \
     &&rm -rf /home/python 

ENV PATH="/usr/local/python/bin:$PATH"

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CMD python3

安装过程参考
https://www.cnblogs.com/yjlch1016/p/9289588.html

anaconda

FROM centos:centos7.5.1804

RUN yum install -y bzip2 wget 

RUN wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh -O ~/anaconda.sh && \
    /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    rm ~/anaconda.sh 

ENV PATH="/opt/conda/bin:$PATH"

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV LANG C.UTF-8 LC_ALL=C.UTF-8

安装过程copy的
https://blog.csdn.net/quincuntial/article/details/79292575

注意的是dockerfile中的环境变量需要用ENV

ENV PATH="/opt/conda/bin:$PATH"

用RUN export 则下层的镜像是使用不了上层定义的环境变量
用 echo “$PATH” >>~/.profile或 ~/.bashrc这种方式,使用bash命令进入容器是可以使用环境变量,但dockerfile下一层命令中依旧不能使用上层写进文件中的环境变量,不过如果source一下文件可能就ok,没有尝试,有兴趣的可以试试

还有,基础镜像中并未进行pip的换源操作,我换源是在具体的应用镜像的dockerfile中换的源,换源可以在dockerfile中使用COPY, 在build镜像是就会copy 上下文中的文件进镜像,当然也可以用RUN echo -e直接生成文件,注意有-e, -e是不忽略具体符号的,如果没有 -e 写进文件中的配置将不会换行,却而代之的是\n字符串
在这里插入图片描述

FROM  anaconda

RUN mkdir -p ~/.pip \
    &&echo -e "[global] \nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" \
    >>~/.pip/pip.conf

RUN echo -e "channels: \n\
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ \n\
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ \n\
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ \n\
show_channel_urls: true \n">>~/.condarc

RUN pip install ......

注意\n号换行符和\中间没有空格,这是为了缩进格式正确

额,如果有想要自己做基础镜像,写dockerfile的,可以参考一下下面的文章,我觉得写的很有参考价值
精简Docker镜像的五种通用方法

我不是博客的生产者,我只是博客的搬运工
感谢大佬的无私奉献,希望这篇博客能对后面的新人有所帮助
还有,如果不允许转载的话,请及时联系我,我会及时删除,谢谢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值