0. 依赖
[root@iZrj9hydhs113jtunf2bvuZ messagecenter]# cat requirements.txt django==3.1.3
1. dockerfile
[root@iZrj9hydhs113jtunf2bvuZ messagecenter]# cat dockerfile FROM python:3.7 ENV PYTHONUNBUFFERED 1 WORKDIR /opt/ ADD messagecenter.tar /opt/ RUN pip install pip -U ADD requirements.txt /opt/ RUN pip install -r requirements.txt ADD run.sh . RUN chmod 755 run.sh ENTRYPOINT [ "/opt/run.sh"]
2. django项目启动命令
[root@iZrj9hydhs113jtunf2bvuZ messagecenter]# cat run.sh #!/bin/bash # 启动任务计划 #/usr/sbin/cron # 最后一行增加任务计划 #sed -i ‘$a* * * * * root python3 /messagecenter/cron/voc_receipt.py‘ /etc/crontab # 启动django项目 cd /opt/ python3 manage.py runserver 0.0.0.0:8000
3. 构建镜像
docker build -t 10messagecenter /opt/messagecenter
4. 启动docker 镜像
docker run -d -it -p 8000:8000 10messagecenter
5. 允许访问
在我们创建的项目里修改setting.py文件 ALLOWED_HOSTS = [‘*‘] #在这里请求的host添加了*