Dockerfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # 拉取镜像
  2. FROM centos:centos7.9.2009
  3. # 配置容器时间
  4. RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
  5. # 添加快捷命令
  6. RUN echo "alias ll='ls -hall'" >> ~/.bashrc && source ~/.bashrc
  7. # 更新yum源
  8. RUN curl -o /etc/yum.repos.d/CentOS7-Aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel-7-Aliyun.repo http://mirrors.aliyun.com/repo/epel-7.repo
  9. RUN yum clean all && yum makecache && yum -y update
  10. RUN yum install -y kde-l10n-Chinese
  11. # 设置系统编码
  12. ENV LANG=zh_CN.UTF-8
  13. # 设置vi编码(防止中文乱码)
  14. RUN grep -qxF 'set encoding=utf8' /etc/virc || echo 'set encoding=utf8' >> /etc/virc
  15. WORKDIR /opt
  16. # 安装 python3.8.10 gcc相关配置
  17. RUN yum --exclude=kernel* update -y && yum groupinstall -y 'Development Tools' && yum install -y gcc openssl-devel bzip2-devel libffi-devel mesa-libGL
  18. # python3.8.10下载与解压缩
  19. RUN curl -o python3.8.10.tgz https://mirrors.huaweicloud.com/python/3.8.10/Python-3.8.10.tgz && tar -zxvf python3.8.10.tgz
  20. # 设置Python3虚拟环境路径
  21. ENV VIRTUAL_ENV=/usr/local/python38
  22. # 切换路径
  23. WORKDIR /opt/Python-3.8.10
  24. # 创建安装目录, 指定安装目录
  25. RUN mkdir $VIRTUAL_ENV && ./configure --prefix=$VIRTUAL_ENV
  26. # 编译、安装
  27. RUN make -j 8 && make altinstall
  28. # 创建python3的软连接
  29. RUN rm -rf /usr/bin/python3 /usr/bin/pip3 && ln -s $VIRTUAL_ENV/bin/python3.8 /usr/bin/python3 && ln -s $VIRTUAL_ENV/bin/pip3.8 /usr/bin/pip3
  30. # 更换pip源&更新pip
  31. RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip3 install --upgrade pip
  32. # python3虚拟环境加入系统环境变量
  33. ENV PATH="$VIRTUAL_ENV/bin:$PATH"
  34. # 指定应用安装目录
  35. WORKDIR /app
  36. # 复制当前目录文件到容器/app目录下
  37. COPY requirements.txt requirements.txt
  38. # 安装python项目依赖
  39. RUN pip3 install -r requirements.txt
  40. # 指定工作目录
  41. WORKDIR /mnt