使用Docker搭建Django,Nginx,R,Python部署环境
转载自https://blog.csdn.net/The_One_is_all/article/details/76063968
基本环境:
Ubuntu 16.10
docker 17.06.0-ce
压缩自己的项目文件
1.这里需要注意的是,在压缩的时候,也需要把自己的需要的Python包写在requirement.txt,这样搭建环境的时候才会知道你需要什么包,才能一起安装,我的项目的requirement.txt 内容如下。
Django==1.10.5
rpy2==2.8.5
PyMySQL==0.7.9
numpy==1.13.0
pandas==0.20.2
scikit-learn==0.18.1
scipy==0.19.0
uwsgi
2.更改自己的settings.py,为Nginx服务器代理设置部署环境
更改的内容如下
STATIC_ROOT = os.path.join(BASE_DIR, 'collect_static')
ALLOWED_HOST = ['*']
注意:这里不能将部署的环境与开发环境的静态文件相同,否则会引起错误。
修改好后运行如下命令:
python manage.py collectstatic
这个时候就可以安心压缩文件了
tar czvf FileName.tar DirName
构建web环境
1.将打包好的项目文件放入web文件夹中
cp /home/haoyu/AAPlatform.tar .
2.编写Dockerfile
这里主要是搭建基础环境
# 基础镜像
FROM ubuntu:16.10
FROM daocloud.io/python:3.5
# 维护者信息
MAINTAINER haoyu <why_oneisall@163.com>
ADD AAPlatform.tar /usr/src/
# app 所在目录
WORKDIR /usr/src/AAPlatform
ENV LD_LIBRARY_PATH=/usr/local/lib
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety main restricted" > /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-updates main restricted" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-updates universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-updates multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-security main restricted" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-security universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ yakkety-security multiverse" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y make
RUN echo "deb http://cran.rstudio.com/bin/linux/ubuntu yakkety/" >> /etc/apt/sources.list
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9
RUN apt-get update
RUN apt-get install -y r-base # r-base-dev r-cran-mgcv r-base-core r-base-html r-recommended
# 安装 app 所需依赖
RUN pip install --no-cache-dir -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
基本上Django和R搭建的环境都在这了。
2.编写start.sh
这里是要把docker的Django运行起来
内容如下:
#!/bin/bash
#
docker build -t aaplatform/django-app .
docker run --name django \
-v /usr/src/AAPlatform \
-v /usr/src/AAPlatform/collect_static \
-p 12000:8000 \
-d feiyu/django-app /usr/local/bin/uwsgi --http :8000 --chdir /usr/src/AAPlatform -w AAPlatform.wsgi
#-d aaplatform/django-app /usr/local/bin/gunicorn myblog.wsgi:application -w 1 -b :8000
搭建Nginx环境
1.编写Dockerfile文件
配置Nginx相关的环境
FROM daocloud.io/nginx
MAINTAINER haoyu <www.haoyu.com>
RUN rm /etc/nginx/conf.d/default.conf
ADD nginx-conf/ /etc/nginx/conf.d/
2.编写Server配置文件
需要将系统默认的配置文件更改一下
在nginx-conf中:
server {
listen 80;
server_name localhost;
charset utf-8;
root /usr/src/AAPlatform;
access_log /var/log/nginx/django.log;
location ^~ /static {
alias /usr/src/AAPlatform/collect_static;
}
location / {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
保证Nginx环境能够构建起来。
3.编写start.sh
让docker运行起来
#!/bin/bash
#
docker build -t nginx .
docker run --name nginx-server \
--link django:web \
-v /www/collect_static \
--volumes-from django \
-p 8888:80 \
-d nginx
整个环境结合
1.构建docker-start.sh
启动web和Nginx
#!/bin/bash
#
cd ./web
echo "start web --------------------------"
./start.sh
cd ../nginx
echo "start nginx-------------------------"
./start.sh
2.编写stop.sh
关闭docker
#/bin/bash
#
sudo docker kill $(docker ps -a -q)
sudo docker rm $(docker ps -a -q)
运行测试
1.运行sh文件
$ ./docker-start.sh
2.访问网站
http://127.0.0.1:8888/login
注意:要访问的是Nginx服务器。
将部署好的镜像文件导出
1.docker save
docker save 00273588addb -o aaplatform.tar aaplatform/django-app:latest
- 1
2.docker load
docker load < aaplatform.tar
使用Docker搭建Django,Nginx,R,Python部署环境的更多相关文章
- 用docker搭建php+nginx+laravel的开发环境
制作镜像 由于官方php:7.2.2-fpm-alpine3.7 镜像不含composer,而单独做一个composer镜像又会依赖php镜像,所以应该在php镜像中添加composer.Docker ...
- django+nginx+uwsgi_cent0s7.4 部署
django+nginx+uwsgi_cent0s7.4 部署 几条命令 # 查看是否有 uwsgi 相关的进程 ps -aux|grep "uwsgi" # 杀死有关 uwsgi ...
- 一.1搭建跨平台的统一python开发环境
搭建跨平台的统一python开发环境: 使用开发环境的好处: 可不用在服务器上直接修改源代码---写的代码首先得入版本库(放git或giitlab中),在本地写代码提交到git中.然后在服务器上git ...
- django+nginx+uwsgi 项目部署
Django虽然自带一个Server,但只能作为开发时测试使用,我们需要一个可以稳定而持续的服务器对网站进行部署,比如Apache, Nginx, lighttpd等,本篇将利用nginx和uWSGI ...
- Docker + node(koa) + nginx + mysql 线上环境部署
在上一篇 Docker + node(koa) + nginx + mysql 开发环境搭建,我们进行了本地开发环境搭建 现在我们就来开始线上环境部署 如果本地环境搭建没有什么问题,那么线上部署的配置 ...
- 利用docker搭建ubuntu+nginx+PHP容器
环境:操作系统(Ubuntu 16.04 64位); php7.1; nginx/1.14.0 基础环境准备: 整体思路:docker pull一个ubuntu镜像,然后在容器中安装ngi ...
- Ubuntu系统搭建django+nginx+uwsgi
1. 在开发机上的准备工作 2. 在服务器上的准备工作 3.安装uwsgi 4.编写uwsgi配置文件,使用配置文件启动uwsgi 5. 安装nginx 6. 收集静态文件 7. 编写nginx配置文 ...
- python 2.7 pip导入django,将python部署到sublime上
1.安装python 2.7,并且导入第三方库django 下载python 2.7,然后把python2.7的python.exe的路径和pip的路径添加到系统环境变量的path路径下. win+R ...
- Django + nginx + uswgi 的部署总结
一.引言 自己小组内写了一个网站,需要部署到远程服务器,搜索了好多资料,但是大部分资料都比较繁琐,并且没有一个教程能够直接从头到尾适合,在部署过程中,我是按照很多教程然后综合试验着逐渐部署成功,其中有 ...
随机推荐
- /etc/fstab 文件如何填写(转)
转载自 http://hi.baidu.com/jingzhongchen/blog/item/8e6f552dcead7ce98b139952.html 看你对/etc/fstab文件了解多少? ...
- 20170413B端业务访问故障排查思路
现象: 1.全国用户电视端页面无法显示,刷不出版面. 2.后端服务无法打开,报错,504,502 显示服务器端业务故障超时. 3.其他业务也出现缓慢情况,并不严重. 排查: 1.系统服务排查,常规 ...
- iostat lsof
转至:http://www.51testing.com/html/48/202848-242043.html 命令总结: 1. top/vmstat 发现 wa%过高,vmstat b >1: ...
- c++ string需要注意的地方
There are multiple answers based on what you are doing with the string. 1) Using the string as an id ...
- 软工1816 · Alpha冲刺(2/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 与前后端敲定接口设计的细节 重新理清业务逻辑,对项目最初的设想进行一定修正 跟 ...
- lintcode-14-二分查找
二分查找 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. 样例 在数组 ...
- grid++json页面数据传入
最近遇到一个问题,就是要用Grid++做页面数据报表打印,但是翻了Grid++文档就是没有直接从页面上传数据的,都是要加载txt文档,填写txt文档的url.自己尝试直接页面上传JSON数据到Grid ...
- 网上的腾讯php面试题 (有答案版本)
一.PHP开发部分1.合并两个数组有几种方式,试比较它们的异同 答:1.array_merge()2.’+’3.array_merge_recursive array_merge 简单的合并数组arr ...
- Matlab 中的varargin/nargin varargout/nargout
Varargin = var+ arg+ in = variable length(可变长) input argument(输入参数) list(列表) :允许调用该函数时根据需要改变输入参数的个数 ...
- 【转】Jsp自定义标签详解
一.前言 原本是打算研究EXtremeComponents这个jsp标签插件,因为这个是自定义的标签,且自身对jsp的自定义标签并不是非常熟悉,所以就打算继续进行扫盲,开始学习并且整理Jsp自定义标签 ...