用Django写了个小网站,准备往云主机上挂起来,用docker部署方便直接
架构上 准备 nginx一个dokcer,uwsgi和django一个docker,mysql一个docker。三个docker组网访问
先pull下来三个docker的官方镜像
docker pull nginx
docker pull mysql
docker pull ubuntu:14.4
pull下来如图
- 创建一个docker网络
docker network create -d bridge my-net
- run ubunru 连接到my-net网络上 取名为magellan
docker run -itd --name=magellan --network my-net -p 8080:80 ubuntu:14.04 /bin/bash
- run mysql 挂载主机的/root/docker_mysql_data卷为mysql的数据卷
docker run -d --name=my-sql --network my-net -p 33060:3306 -v /root/docker_mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password mysql:latest
- 进入magellan 更换apt源
对于ubuntu14.04
用
替换deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
/etc/apt/sources.list
apt-get update
apt-get install python3-pip
apt-get install wget -y && apt-get install unzip -y
接下来下载好Django 安装好模块,配置好数据库,就可以run起来了
image.png
数据库的host 就是刚才配置的my-sql - wsgi 和django的连接
pip3 install uwsgi
- Django自带了一个wsig.py, 直接运行
uwsgi --http :8000 --wsgi-file wsgi.py
。报错
ImportError: No module named 'magellan'
将wsgi.py换到项目下
- nginx
dokcer run --name my-nginx --network my-net -v /root/www/nginx.conf:/etc/nginx/conf.d/magellan.conf -itd -p 80:80 nginx:latest /bin/bash
- 直接访问ip nginx 表示启动成功
Welcome to nginx!
- 配置nginx文件
docker run -d --name=my-sql --network my-net -p 33060:3306 -v /usr/local/magellan/mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=4F1TaPHo6Khn988U mysql:latest
docker run -itd --name=my-magellan --dns 114.114.114.114 --network my-net -p 8080:8080 -v /usr/local/magellan/static:/usr/local/magellan/static -v /usr/local/magellan/media:/usr/local/magellan/media ubuntu:14.04
docker run -itd --name=my-nginx --dns 114.114.114.114 --network my-net -p 80:80 -v /usr/local/static:/usr/local/magellan/static -v /usr/local/media:/usr/local/magellan/media nginx:latest
superviso 守护 uwsgi
apt-get update
apt-get install curl
apt-get install vim
apt-get install python3
apt-get install python3-pip
pip3 install uwsgi
soc/magellan.log
网友评论