程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[docker] the first time to deploy Django project with docker -20220209

編輯:Python

1. Premise :

1.1 Django The project should be able to start normally on this machine .

1.2 docker desktop Normal installation .

1.3 Django Specify the port when starting the server (python3 manage.py runserver 0.0.0.0:8000).

2. Create project & To configure docker

2.1 Create project directory

establish 20220209-Django_images, Put it in Django_PP and dockerfile.

Django_PP Next new package. Start this machine django Copy all items to package below .

2.2 establish dockerfile file

FROM python:3.8
COPY ./Django_PP /code
WORKDIR /code/package
# Installation dependency 
RUN pip install -r requirements.txt
# to grant authorization 
RUN chmod 777 /code/package/runserver.sh
# Exposed port 
EXPOSE 8000
# sh yes linux Command line 
CMD ["/bin/sh","/code/package/runserver.sh"]

2.3 establish requirements.txt file

Use pip freeze Get the installed Python package
https://blog.csdn.net/sigmarising/article/details/85235062

2.4 To write runserver.sh

2.5 create mirror image

docker build -t pp4 .

2.6 Create a container container, And start the

docker run -it -p 8000:8000 --name pp_container4 pp4

Input docker ps See what's running container.

3. open Django website


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved