Docker之利用Dockerfile创建Nginx镜像

镜像获取方法

1、使用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、通过公共仓库搜索下载(我已经上传了)
docker search benyoo/nginx_build
docker pull benyoo/nginx_build
使用方法

docker run -dti --name=nginx_build \
-p 80:80 -p 443:443 \
-v /home/wwwroot:/home/wwwroot \
benyoo/nginx_build
Dockerfile文件详情

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年11月17日 星期二 10时29分55秒
#########################################################################
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>
    <h1 style="text-align:center;">
        <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>
    </h1>
    <h1 style="text-align:center;">
        <span style="line-height:1.5;color:#E53333;">^_^┢┦aΡpy&nbsp;</span>
    </h1>
</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 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;"
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;
}

时间: 2024-10-27 23:32:39

Docker之利用Dockerfile创建Nginx镜像的相关文章

Docker之利用Dockerfile创建ShadowSocks多用户版镜像,实现快速集群式部署

镜像获取 [root@docker-node01 ~]# docker search shadowsocksr_manyuser NAME                           DESCRIPTION                  STARS     OFFICIAL   AUTOMATED benyoo/shadowsocksr_manyuser   基于ShadowSocksR版的manyuser封装   0                    [root@docker-

Docker for Devs:创建开发镜像

本文讲的是Docker for Devs:创建开发镜像[编者的话]本文介绍如何利用Docker本地化卷来搭建开发环境. [3 天烧脑式容器存储网络训练营 | 深圳站]本次培训以容器存储和网络为主题,包括:Docker Plugin.Docker storage driver.Docker Volume Pulgin.Kubernetes Storage机制.容器网络实现原理和模型.Docker网络实现.网络插件.Calico.Contiv Netplugin.开源企业级镜像仓库Harbor原理及

Docker dockerfile创建Eclipse镜像初试

抽空初步阅读了Docker技术入门与实战 [Kindle电子书] http://www.cnblogs.com/2018/p/4600116.html 现在想首先在开发环境下引入统一的环境,由于开发中都使用了eclipse环境.因此需要搭建1个包括eclipse的镜像. https://registry.hub.docker.com/search?q=eclipse&searchfield= 这个官网有部分可以直接使用的镜像 其中1个使用 docker pull iwakoshi/eclipse

dockerfile 创建 ssh 镜像

一.编辑Dockerfile vim Dockerfile # SSH # Version 0.0.1 # IMAGES FROM 192.168.0.216:5000/centos # MAINTAINER MAINTAINER hongxue hongxue@showjoy.com # YUM RUN yum -y update RUN yum -y install vim net-tools openssh-server # SSH RUN ssh-keygen -t dsa -f /et

Dockerfile 创建 tomcat 镜像

一.编写Dockerfile文件 下图中的channel是我自己公司所用到的,它只是普通的tomcat,只是我丢了一个ROOT.war包进去,大家也可以使用默认的ROOT.war. # Tomcat # Version 0.0.1 # GET_IMAGE FROM 192.168.0.216:5000/centos # MAINTAINER_INFO MAINTAINER hongxue hongxue@showjoy.com RUN yum -y install vim RUN yum -y

Docker之利用 Dockerfile构建 Redis 服务的教程

Dockerfile   ENV REDIS_VERSION=3.2.1 ENV REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz \         REDIS_DOWNLOAD_SHA1=26c0fc282369121b4e278523fce122910b65fbbf   RUN \         REDIS_FILE=${REDIS_DOWNLOAD_URL##*/} &&a

Docker使用Dockerfile创建支持ssh服务自启动的容器镜像_docker

本文实例为大家分享了Dockerfile创建支持ssh服务自启动的容器镜像,供大家参考,具体内容如下 1. 首先创建一个Dockerfile文件,文件内容如下 # 选择一个已有的os镜像作为基础 FROM centos:centos6 # 镜像的作者 MAINTAINER Fanbin Kong "kongxx@hotmail.com" # 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no RUN yum install -y openssh

详解使用Dockerfile创建带Apache服务的CentOS Docker镜像_docker

使用Dockerfile创建带Apache服务的CentOS Docker镜像 在宿主机上准备的文件清单: Dockerfile #启动ssh和apache服务的角本 run.sh 以上文件都放到/root/apache_centos目录下 mkdir -p /root/apache_centos cd /root/apache_centos 基础镜像:以镜像centos为基础的开放SSH服务的镜像 [root@localhost apache_centos]# docker images RE

Centos 7.x 利用 Dockerfile 来创建Beego Framework

Dockerfile包含创建镜像所需要的全部指令.基于在Dockerfile中的指令,我们可以使用Docker build命令来创建镜像.通过减少镜像和容器的创建过程来简化部署 Dockerfile 基本的语法是 使用#来注释 FROM 指令告诉 Docker 使用哪个镜像作为基础,这里我从自己的私有镜像库获取 MAINTAINER:设置该镜像的作者 RUN开头的指令会在创建中运行,比如安装一个软件包,在这里使用 yum 来安装了一些软件,在shell或者exec的环境下执行的命令.RUN指令会