Docker rapid deployment to the cloud server Django project

Project structure:

 

 

 1,dockerfile

FROM python:3.7
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY pip.conf /root/.pip/pip.conf
COPY requirements.txt /usr/src/app/
RUN pip install -r /usr/src/app/requirements.txt
RUN rm -rf /usr/src/app
COPY . /usr/src/app
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000"]

2,pip.conf

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

3,requirements.txt

Here can be automatically generated command 

pip freeze > requirements.txt

4, upload the entire project to the server

Note: Virtual environments do not have added to the list 
because docker will automatically download to rely 
and virtual environments occupied 100M + - space, time enough to upload 5+ minutes, etc.

 

5, image generating docker

 CD project and dockerfile same level directory, which is directory project (note behind  . not omitted)

docker build -t hello_python .

dockerfile buid mirror when the image size at every turn 800+ M, long wait. 

Execution docker images

 

 6, open container

docker run -it --rm -p 8000:8000 --name hello hello-python:latest

Note: The second number is dockerfile port 8000 decision

Results are as follows:

 

 ** Note exposed port number

Guess you like

Origin www.cnblogs.com/xcsg/p/11517107.html