Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 506403
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2017-07-07 11:41:39

Dockerfile文件详情

FROM centos:6.7
 
MAINTAINER from hanye131 hz7726@163.com
 
RUN yum clean all && \
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-* && \
yum install -y epel-release && \
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 && \
yum makecache && \
yum install -y pcre-devel openssl-devel zlib-devel gd-devel tar gcc wget git supervisor
 
RUN groupadd --system www && \
useradd --system --gid www www && \
mkdir -p {/var/log/wwwlogs,/var/run/nginx,/var/lock}
 
RUN wget -c && \
git clone https://github.com/cuber/ngx_http_google_filter_module.git && \
git clone && \
git clone
 
RUN tar xf nginx-1.12.0.tar.gz && \
cd nginx-1.12.0 && \
./configure --prefix=/usr/local/nginx \
--user=www --group=www \
--error-log-path=/var/log/wwwlogs/error.log \
--http-log-path=/var/log/wwwlogs/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-pcre \
--with-ipv6 \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_mp4_module \
--with-http_image_filter_module \
--with-http_addition_module \
--http-client-body-temp-path=/usr/local/nginx/client/ \
--http-proxy-temp-path=/usr/local/nginx/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi \
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module \
--add-module=../ngx-fancyindex && \
make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && \
rm -rf ../{ngx_http*,ngx-fancyindex,nginx-1.12.0*}
 
ADD nginx.conf /usr/local/nginx/conf/nginx.conf
 
ADD nginx.sh /nginx.sh
RUN chmod +x /nginx.sh
 
VOLUME ["/home/wwwroot"]
 
EXPOSE 80 443
 
ENTRYPOINT ["/nginx.sh"]
 
CMD ["nginx"]
nginx.sh详情
#!/bin/sh
#########################################################################
# File Name: nginx.sh
# Author: hanye131    
# Email: hz7726@163.com
# Version: 1.0
#########################################################################
PATH=/bin:/usr/local/nginx/sbin:$PATH
Nginx_Install_Dir=/usr/local/nginx
 
set -e
 
if [ -n "$TIMEZONE" ]; then
    rm -rf /etc/localtime && \
    ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime
fi
 
if [ "${1:0:1}" = '-' ]; then
    set -- nginx "$@"
fi
 
if [ -z "$DATA_DIR" ]; then
    DATA_DIR=/home/wwwroot
fi
 
sed -i "s@/home/wwwroot@$DATA_DIR@" $Nginx_Install_Dir/conf/nginx.conf
mkdir -p ${DATA_DIR}
[ ! -f "$DATA_DIR/index.html" ] && echo '


   


        hellow docker nginx
  


 


' > $DATA_DIR/index.html
chown -R $DATA_DIR
 
CPU_num=$(awk '/processor/{i++}END{print i}' /proc/cpuinfo)
if [ "$CPU_num" == '2' ];then
    sed -i 's@^worker_processes.*@worker_processes 2;\nworker_cpu_affinity 10 01;@' $Nginx_Install_Dir/conf/nginx.conf
elif [ "$CPU_num" == '3' ];then
    sed -i 's@^worker_processes.*@worker_processes 3;\nworker_cpu_affinity 100 010 001;@' $Nginx_Install_Dir/conf/nginx.conf
elif [ "$CPU_num" == '4' ];then
    sed -i 's@^worker_processes.*@worker_processes 4;\nworker_cpu_affinity 1000 0100 0010 0001;@' $Nginx_Install_Dir/conf/nginx.conf
elif [ "$CPU_num" == '6' ];then
    sed -i 's@^worker_processes.*@worker_processes 6;\nworker_cpu_affinity 100000 010000 001000 000100 000010 000001;@' $Nginx_Install_Dir/conf/nginx.conf
elif [ "$CPU_num" == '8' ];then
    sed -i 's@^worker_processes.*@worker_processes 8;\nworker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;@' $Nginx_Install_Dir/conf/nginx.conf
else
    echo Google worker_cpu_affinity
fi
 
exec "$@" -g "daemon off;"
nginx.xonf配置详情
user www www;
worker_processes auto;
 
error_log /var/log/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
 
events {
    use epoll;
    worker_connections 51200;
}
 
http {
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    server_tokens off;
    tcp_nodelay on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
 
    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
    gzip_disable  "msie6";
 
    #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
 
    server {
        listen 80;
        server_name -;
        root /home/wwwroot;
        index index.html index.php index.jsp;
        access_log /var/log/wwwlogs/access_nginx.log combined;
 
        location /status {
            stub_status on;
            auth_basic "WebServer Status";
        }
 
#        location ~ .*\.(php|php5)?$ {
#            #fastcgi_pass remote_php_ip:9000;
#            fastcgi_pass unix:/dev/shm/php-cgi.sock;
#            fastcgi_index index.php;
#            include fastcgi.conf;
#        }
 
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
            expires 30d;
        }
 
        location ~ .*\.(js|css)?$ {
            expires 7d;
        }
    }
 
##########################vhost#####################################
    include vhost/*.conf;
}


构建项目
构建镜像容器
  docker build -t nginx_build:1.12.0 ./
构建启动项目
docker run -itd --name nginx_build -p 80:80 -p 443:443 -v $PWD/nginx:/home/wwwroot nginx_build:1.12.0
docker images 查看项目
docker ps 查看启动
docker logs nginx_build 查看启动日志
阅读(1254) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~