Example of how Docker deploys a Django project
Using docker to deploy django project is also very simple, quite good, share
environment
By default, you have docker installed.
Django project approximate structure
(p3s) [root@opsweb]# tree opswebopsweb├── apps├── logs├── manage.py├── media├── opsweb├── README.md├── requirements.txt└── static
Writing Dockerfile
This specifies that the Python version is officially provided by docker
"0.0.0: 8000" Here I open port 8000 in the container FROM python:3.6RUN mkdir -p /usr/src/appCOPY pip.conf /root/.pip/pip.confCOPY opsweb /usr/src/app/COPY run_web. sh/usr/src/app/RUN pip install -r /usr/src/app/requirements.txtWORKDIR /usr/src/appCMD [ "sh", "./ run_web.sh"]
Writing pip files
Here is to use the mirror pip install faster use aliyun source
[global]index-url = http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com
Complete directory structure
[root@opsweb]# lsDockerfile opsweb pip.conf run_web.sh
build mirror
docker build -t ops:v0.1 .Sending build context to Docker daemon 4.849 MBStep 1 : FROM python:3.6 ---> 3e4c2972dc8dStep 2 : RUN mkdir -p /usr/src/app ---> Running in 8ddd929f5c18 ---> 89dc0a1ffdf0Removing intermediate container 8ddd929f5c18Step 3 : COPY pip.conf /root/.pip/pip.conf ---> 5a4a165fed90Removing intermediate container 37f3fdc7e5d2Step 4 : COPY opsweb /usr/src/app/opsweb ---> f602e72ffd4cRemoving intermediate container 8d4bb616916dStep 5 : COPY opsweb/requirements.txt /usr/src/app/ ---> 6fe11a6fcbe0Removing intermediate container faeadee32fedStep 6 : RUN pip install -r /usr/src/app/requirements.txt ---> cc09c17d53daRemoving intermediate container d7b45bec6993Step 7 : WORKDIR /usr/src/app ---> Running in c22dfdddbe81 ---> c5c944b6df45Removing intermediate container c22dfdddbe81Step 8 : CMD python ./ manage.py runserver 0.0.0.0:8000 ---> Running in 29d5f0f53f6e ---> 10d37173fd13Removing intermediate container 29d5f0f53f6eSuccessfully built 10d37173fd13
conclusion
So the image is built, and then you can directly docker run -p8000:8000 ops:v0.1 -d start on the line, or you can deploy to k8s is also very simple here will not go into detail.
The above is all the content of this article, I hope to help everyone's study, but also hope that everyone a lot of support.