本文源自于python
https://dzone.com/articles/how-to-deploy-a-django-application-with-dockerlinux
只不过这里用本身的方式再简述一遍。并且使用了较新的Python 和django 版本docker
由于如今大部分都是使用windows环境的,因此我就没有使用linux或者文中所说的“Alibaba Cloud ECS Linux instance”django
步骤:windows
1.安装Docker windows版本app
2.安装python 及 djangoui
3.建立django程序spa
4.编辑DockerfIle3d
# set the base image FROM python:3 # File Author / Maintainer MAINTAINER Esther #add project files to the usr/src/app folder ADD . /usr/src/app #set directoty where CMD will execute WORKDIR /usr/src/app COPY requirements.txt ./ # Get pip to download and install requirements: RUN pip install --no-cache-dir -r requirements.txt # Expose ports EXPOSE 8000 # default command to execute CMD exec gunicorn djangoapp.wsgi:application --bind 0.0.0.0:8000 --workers 3
5.编辑requirements.txtcode
#requirements.txt Django==2.1 gunicorn==19.9.0
最终生成的目录结构以下:
7.在该目录下,运行CMD命令。执行建立镜像的命令
docker build -t django_application_image .
8.运行该容器
docker run -p 8000:8000 -i -t django_application_image
至此,容器已经成功运行起来了,而且服务端口已经映射到 8000 端口了。
至于退出容器,能够使用
若是想再中止该容器,能够执行
docker stop imageid