制作整合centos7和python3的docker基礎鏡像


docker安裝

linux mint下docker的安裝步驟參照**linux mint 19 安裝docker **

基礎鏡像制作

  • 提升到root權限
  • 建立空文件夾images
  • images文件夾中創建文件dockerfileDockerfile(不需要后綴名),文件內容如下:
FROM centos:7.6.1810
MAINTAINER username # 指定作者信息
RUN set -ex \
    # 預安裝所需組件
    && yum install -y wget tar libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make initscripts \
    && wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz \
    && tar -zxvf Python-3.5.0.tgz \
    && cd Python-3.5.0 \
    && ./configure prefix=/usr/local/python3 \
    && make \
    && make install \dock
    && make clean \
    && rm -rf /Python-3.5.0* \
    && yum install -y epel-release \
    && yum install -y python-pip
# 設置默認為python3
RUN set -ex \
    # 備份舊版本python
    && mv /usr/bin/python /usr/bin/python27 \
    && mv /usr/bin/pip /usr/bin/pip-python2.7 \
    # 配置默認為python3
    && ln -s /usr/local/python3/bin/python3.5 /usr/bin/python \
    && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
# 修復因修改python版本導致yum失效問題
RUN set -ex \
    && sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/bin/yum \
    && sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/libexec/urlgrabber-ext-down \
    && yum install -y deltarpm
# 基礎環境配置
RUN set -ex \
    # 修改系統時區為東八區
    && rm -rf /etc/localtime \
    && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && yum install -y vim \
    # 安裝定時任務組件
    && yum -y install cronie
# 支持中文
RUN yum install kde-l10n-Chinese -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
# 更新pip版本
RUN pip install --upgrade pip
ENV LC_ALL zh_CN.UTF-8

  • images路徑下執行命令docker build -t centos-with-python .,注意后面的.不能去掉。
root@ThinkPad-X280:~# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
centos-with-python   latest              e96f7cfd1865        5 days ago          1.09GB
python               3                   a2aeea3dfc32        12 days ago         932MB
ubuntu               16.04               5f2bf26e3524        3 weeks ago         123MB
ubuntu               latest              775349758637        3 weeks ago         64.2MB
centos               7.6.1810            f1cb7c7d58b7        8 months ago        202MB
python               2.7.15              afc94ac1e19b        9 months ago        925MB

其他

制作鏡像過程中需要下載一些依賴,如果下載速度過慢可以考慮更換docker的源,在lnux mint的操作步驟具體如下:

  • root權限進入/etc/docker;
  • 修改daemon.json為如下內容:
# 配置多個國內docker源
{

    "registry-mirrors":["https://registry.docker-cn.com", "http://hub-mirror.c.163.com","https://pee6w651.mirror.aliyuncs.com"]

}

  • 重啟dockerservice docker restart
  • 使用pip安裝第三方包時如果速度過慢,可用通過-i參數指定源,例如:
sudo pip3 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simpl


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM