Docker uses Dockerfile to create nginx mirrors

Source: Internet
Author: User
Tags gpg mkdir centos git clone docker run

Image Capture Method

1. Create with Dockerfile
wget-o-Http://www.dwhd.org/wp-content/uploads/2015/11/Dockerfile1 >dockerfile
wget-o-http://www.dwhd.org/wp-content/uploads/2015/11/nginx.conf >nginx.conf
wget-o-Http://www.dwhd.org/wp-content/uploads/2015/11/run.sh1 >run.sh
Docker build-t nginx_build:1.9.5./
2, through the public warehouse search download (I have uploaded)
Docker Search Benyoo/nginx_build
Docker Pull Benyoo/nginx_build
How to use

Docker run-dti--name=nginx_build \
-P 80:80-p 443:443 \
-v/home/wwwroot:/home/wwwroot \
Benyoo/nginx_build
Dockerfile File Details

From centos:6.7

Maintainer from www.dwhd.org by Lookback (mondeolove@gmail.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 http://nginx.org/download/nginx-1.9.5.tar.gz && \
git clone https://github.com/cuber/ngx_http_google_filter_module.git && \
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git && \
git clone https://github.com/aperezdc/ngx-fancyindex.git

RUN tar xf nginx-1.9.5.tar.gz && \
CD nginx-1.9.5 && \
./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.9.5*}

ADD nginx.conf/usr/local/nginx/conf/nginx.conf

ADD run.sh/run.sh
RUN chmod +x/run.sh

VOLUME ["/home/wwwroot"]

Expose 80 443

entrypoint ["/run.sh"]

CMD ["Nginx"]
#!/bin/sh
#########################################################################
# File Name:run.sh
# Author:lookback
# email:admin#dwhd.org
# Version:
# Created time:2015 Year November 17 Tuesday 10:29 55 seconds
#########################################################################
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 ' <p>

<span style= "line-height:1.5;" ><span style= "color: #337FE5;" >hello world! This nginx!</span><br/>
</span><span style= "Line-height:1.5;color: #E53333;" >welcome to use docker!</span>

<span style= "Line-height:1.5;color: #E53333;" > ^_^ ┢┦aρpy&nbsp;</span>
</p>
<p>
<br/>
</p>
' > $DATA _dir/index.html
Chown-r www.www $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 01;@ ' $Nginx _install_dir/conf/nginx.conf
elif ["$CPU _num" = ' 3 '];then
Sed-i ' s@^worker_processes.* @worker_processes 3;\nworker_cpu_affinity 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;"
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 8k;
& nbsp;   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 have a lot of static files to serve through Nginx then caching of the files ' metadata (not the actual files ' Conte NTS) 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.