Public Repository

Last pushed: 7 months ago
Short Description
Short description is empty for this repo.
Full Description

1:安装docker,确认版本,Xenial 16.04 (LTS)
https://docs.docker.com/engine/installation/linux/ubuntu/
坑:无法挂载硬盘,内核问题
https://github.com/docker/docker/issues/29798

2:运行docker的容器
docker run -p 80:80 -itd -v /home:/home 0ef2e08ed3fa
3.1:更新并安装初步python环境和虚拟环境
apt-get update
apt-get install vim
apt-get install python3-pip
pip3 install virtualenv

3:安装django+uwsgi+nginx
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
3.1:virtualenv
virtualenv /home/env001
source /home/env001/bin/activate
3.2:django
pip install django==1.10.6
pip install pillow==4.0.0
pip install jieba==0.38
pip install xpinyin==0.5.5
pip install xlrd==1.0.0
pip install pymysql
3.3:uwsgi
pip install uwsgi
uwsgi --http :80 --wsgi-file test.py 测试uwsgi
python manage.py runserver 0.0.0.0:80 测试django
uwsgi --http :80 --module testdjango.wsgi 测试uwsgi
3.4:nginx
apt-get install nginx
/etc/init.d/nginx start
3.4.1:配置nginx
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configure-nginx-for-your-site
修改:
listen 80;
/media {alias /home/testdjango/media}
/static {alias /home/testdjango/static};
include;/etc/nginx/uwsgi_params
快捷链接:
ln -s /home/nginx/test_nginx.conf /etc/nginx/sites-enabled/
重启:
/etc/init.d/nginx restart
3.5:测试nginx+uwsgi
uwsgi --socket :8000 --wsgi-file test.py
3.5.1:用sock替换端口
修改nginx配置
unix:///home/uwsgi/testdjango.sock
/etc/init.d/nginx restart
3.5.2:测试
uwsgi --socket testdjango.sock --wsgi-file test.py
坑(/var/log/nginx/error.log):unix:///home/uwsgi/testdjango.sock failed (2: No such file or directory)
uwsgi --socket /home/uwsgi/testdjango.sock --wsgi-file test.py --chmod-socket=666
3.5.3:测试django程序
uwsgi --socket /home/uwsgi/testdjango.sock --module testdjango.wsgi --chmod-socket=666
3.6:编写test_uwsgi.ini
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configuring-uwsgi-to-run-with-a-ini-file
chmod-socket = 666
3.6.1:运行
uwsgi --ini /home/uwsgi/test_uwsgi.ini

4:退出虚拟环境后修正uwsgi
deactivate
pip install uwsgi
uwsgi --ini /home/uwsgi/test_uwsgi.ini

5:上帝模式
mkdir /etc/uwsgi
mkdir /etc/uwsgi/vassals
ln -s /home/uwsgi/test_uwsgi.ini /etc/uwsgi/vassals/
uwsgi --emperor /etc/uwsgi/vassals

6:外部执行
docker exec 42bb58fcb232 uwsgi --emperor /etc/uwsgi/vassals

7:把以上步骤保存为一个image
docker commit 42bb58fcb232 jish:001
docker tag 5660ccff2618 jianshaobh/ubuntu:001
docker push jianshaobh/ubuntu

Docker Pull Command
Owner
jianshaobh

Comments (2)
jianshaobh
7 months ago

#tag002来运行django项目
1:下载镜像
docker pull jianshaobh/ubuntu:002
2:新建运行一个容器
docker run -p 80:80 -itd -v /home:/home 530d36149f18
3:上传django项目到home目录
4:启动nginx
docker exec 3b1429ffc0bd /etc/init.d/nginx start
5:配置/home/ini/nginx/coupon_nginx.conf
upstream django {
server unix:///home/ini/coupon.sock;
}

server {
listen 80;
server_name 142.4.210.223;
charset utf-8;

client_max_body_size 100M;

location /media  {
    alias /home/coupon/media;
}

location /static {
    alias /home/coupon/static;
}

location / {
uwsgi_send_timeout 600;
    uwsgi_connect_timeout 600;
    uwsgi_read_timeout 600;
    uwsgi_pass  django;
    include     /etc/nginx/uwsgi_params;
}

}
6:配置/home/ini/uwsgi/coupon_uwsgi.ini
[uwsgi]
chdir = /home/coupon
module = coupon.wsgi
home = /env001

master = true
processes = 10
socket = /home/ini/coupon.sock
daemonize=/home/ini/uwsgi.log
chmod-socket = 666

vacuum = true

7:检测nginx语法和重启
nginx -t
service nginx restart
8:启动uwsgi
uwsgi --emperor /etc/uwsgi/vassals
9:设置django项目
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

jianshaobh
7 months ago

#tag002更新
1:安装docker,确认版本,Xenial 16.04 (LTS)
https://docs.docker.com/engine/installation/linux/ubuntu/
坑:无法挂载硬盘,内核问题
https://github.com/docker/docker/issues/29798

2:运行docker的容器
docker run -p 80:80 -itd -v /home:/home 0ef2e08ed3fa

更新并安装初步python环境和虚拟环境
apt-get update
apt-get install vim
apt-get install python3-pip
pip3 install --upgrade pip
pip3 install virtualenv

3:安装django+uwsgi+nginx
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

virtualenv安装
virtualenv env001
source env001/bin/activate

django和需要的包
pip install django==1.10.6
pip install pillow==4.0.0
pip install jieba==0.38
pip install xpinyin==0.5.5
pip install xlrd==1.0.0
pip install pymysql

4:nginx
deactivate
apt-get install nginx
/etc/init.d/nginx start

配置nginx的conf
参考http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configure-nginx-for-your-site

/home/ini/nginx/coupon_nginx.conf
修改:
server unix:///home/ini/coupon.sock;
listen 80;
server_name 142.4.210.223;
alias /home/coupon/media;
alias /home/coupon/static;
include /etc/nginx/uwsgi_params;

快捷链接
ln -s /home/ini/nginx/coupon_nginx.conf /etc/nginx/sites-enabled/

重启:
/etc/init.d/nginx restart

5:安装uwsgi,编写coupon_uwsgi.ini
pip3 install uwsgi
编写coupon_uwsgi.ini
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configuring-uwsgi-to-run-with-a-ini-file

[uwsgi]
chdir = /home/coupon
module = coupon.wsgi
home = /env001

master = true
processes = 10
socket = /home/ini/coupon.sock
chmod-socket = 666
vacuum = true

6:上帝模式
mkdir /etc/uwsgi
mkdir /etc/uwsgi/vassals
ln -s /home/ini/uwsgi/coupon_uwsgi.ini /etc/uwsgi/vassals/
uwsgi --emperor /etc/uwsgi/vassals

7:上传django到/home
修改settings.py
允许host,收集静态文件,数据库同步

8:保存并上传版本
docker commit 60c977449106 jianshaobh/ubuntu:002
docker login
docker push jianshaobh/ubuntu:002