1.在任意一个地方创建文件夹docker

mkdir docker

  2.进入文件夹并且下载一个django2.1.7的包以及一个epel.repo

cd docker
wget https://media.djangoproject.com/releases/2.1/Django-2.1.7.tar.gz
wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

  3.在此文件夹下两个文件Dockfile和run.sh

  dockerfile封装docker镜像

  4.编写Dockerfile文件

FROM centos
MAINTAINER TigerLee

ADD epel.repo /etc/yum.repos.d  # 将当前目录的epel.repo文件拷贝到容器的/etc/yum.repos.d目录下
RUN yum update -y  # 运行命令(或yum不是最新的,确保版本比较新)

RUN yum install -y python36
RUN yum install -y python36-pip
RUN pip3 install setuptools   #安装python相关的东西
ADD Django-2.1.7.tar.gz /opt/   #把djang拷贝到/opt/目录下并且解压

WORKDIR /opt/  # 进入/opt目录
RUN mv Django-2.1.7 django  # 运行命令mv

WORKDIR /opt/django    # 进入/opt/django目录
RUN python3 setup.py install #安装django

WORKDIR /opt
RUN django-admin.py startproject qishi

ADD run.sh /opt/qishi/run.sh
WORKDIR /opt/qishi
RUN chmod 777 run.sh
EXPOSE 8000  # 声明容器端口
CMD ["/bin/sh","run.sh"]  # 容器启动时默认执行的命令

FROM centos
MAINTAINER TigerLee

ADD epel.repo /etc/yum.repos.d
RUN yum update -y

RUN yum install -y python36
RUN yum install -y python36-pip
RUN pip3 install setuptools
ADD Django-2.1.7.tar.gz /opt/

WORKDIR /opt/
RUN mv Django-2.1.7 django

WORKDIR /opt/django
RUN python3 setup.py install

WORKDIR /opt
RUN django-admin.py startproject qishi

ADD run.sh /opt/qishi/run.sh
WORKDIR /opt/qishi
RUN chmod 777 run.sh
EXPOSE 8000
CMD ["/bin/sh","run.sh"]

简洁版