一、目录结构:
pip.conf文件:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
requirements.txt文件:
Django==2.2.2
PyMySQL==0.9.3
xlrd==1.2.0
XlsxWriter==1.1.8
xlwt==1.3.0
uWSGI==2.0.18
uwsgitop==0.1
Dockerfile文件:
FROM ubuntu:18.04
# 基础镜像
MAINTAINER yangjianliang <526861348@qq.com>
# 作者
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
# 设置apt源为阿里云源
RUN apt-get clean &&
apt-get update &&
apt-get upgrade -y
# 检查软件包并升级
RUN apt-get update &&
apt-get install -y
python3 &&
apt-get update &&
apt-get install -y
python3-dev
python3-setuptools &&
apt-get update &&
apt-get install -y
python3-pip &&
apt-get update &&
apt-get install -y
language-pack-zh-hans* &&
apt-get update &&
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&
apt-get install -y
tzdata &&
rm -rf /var/lib/apt/lists/*
# 安装软件
COPY pip.conf /root/.pip/pip.conf
# 复制pip配置文件
COPY requirements.txt /home/
# 拷贝requirements.txt
COPY xadmin-django2.zip /home/
# 拷贝xadmin-django2.zip
RUN pip3 install /home/xadmin-django2.zip &&
pip3 install -r /home/requirements.txt
# 安装python依赖库
RUN sed -i '35,36d' /usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py &&
sed -i '145,146d' /usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/operations.py &&
sed -i '93d' /usr/local/lib/python3.6/dist-packages/django/forms/boundfield.py
# 修改Django源码
ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
# 设置环境变量,选择zh_CN.UTF-8作为默认字符集,用以支持中文
ENV PYTHONUNBUFFERED=1
# 设置环境变量,不缓冲,等同于python3 -u
二、打包镜像:
docker build -t django_xadmin .
三、推送到阿里云镜像仓库:
sudo docker login --username=yangjianliang2017 registry.cn-hangzhou.aliyuncs.com
登录阿里云Docker Registry
sudo docker tag 1c389de93b60 registry.cn-hangzhou.aliyuncs.com/yangjianliang/django_xadmin:0.0.1
给本地镜像打tag
sudo docker push registry.cn-hangzhou.aliyuncs.com/yangjianliang/django_xadmin:0.0.1
推送到阿里云镜像仓库
sudo docker pull registry.cn-hangzhou.aliyuncs.com/yangjianliang/django_xadmin:0.0.1
从Registry中拉取镜像
四、从阿里云后台管理界面搜索镜像: