docker安裝部署djanggo和python

weixin_34337265發表於2018-03-21

這幾天需要部署眾家雲官網自動化部署djanggo和python要命的事:
這是寫在自動化部署裡面:


5949949-8ce26e85fe3b35ca.png
image.png
docker image prune -af
sleep 1
docker rm -f zencloud-site
sleep 1
tee zencloud-site/run.sh <<-'EOF'
#!/bin/bash
nohup python /data-web/manage.py runserver >logs/runserver.log 2>&1 &
nohup gunicorn -w4 -b0.0.0.0:8000 zencloudweb.wsgi >logs/gunicorn.log
EOF
tee zencloud-site/Dockerfile <<-'EOF'
FROM python:3.6
RUN mkdir ~/.pip
RUN echo "[global]\ntrusted-host=mirrors.aliyun.com\nindex-url=https://mirrors.aliyun.com/pypi/simple/\n" > ~/.pip/pip.conf
ENV DJANGO_VERSION 1.11
RUN pip install --no-cache-dir pymysql django-ckeditor gunicorn markdown pillow django=="$DJANGO_VERSION"
EXPOSE 8000
RUN mkdir -p /data-web
WORKDIR /data-web
COPY run.sh /run.sh
RUN chmod +x /run.sh
CMD ["sh", "/run.sh"]
EOF
docker build zencloud-site/ -t zencloud-site
docker run -d -p 8020:8000 --name zencloud-site -v /root/zencloud-site/data-web:/data-web/ -v /root/zencloud-site/logs:/data-web/logs/ zencloud-site

這裡就安裝好啦:
可以進入容器內部檢視安裝的東西: pip freeze


5949949-2289ecd851b1d0e5.png
image.png

在python裡面檢視資料庫連結情況:
pymysql.connect(host="111.41.114.226",user="zenhome_test", password="root",db="zencloud_site",port=3306)


5949949-4bd207927d331e06.png
image.png

相關文章