1、目錄結構:python
pip.conf文件:mysql
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
requirements.txt文件:git
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文件:sql
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
2、打包鏡像:docker
docker build -t django_xadmin .django
3、推送到阿里雲鏡像倉庫:ubuntu
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中拉取鏡像ui
4、從阿里雲後臺管理界面搜索鏡像:阿里雲