搭建django的docker環境
阿新 • • 發佈:2021-08-21
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 runserver0.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添加了*用一個例子來演示會更加清晰