Build nginx in centos in Docker

Build nginx in centos in Docker — Собираем nginx в докере centos

docker pull centos:latest

Запускаем докер

docker run --privileged -d --restart always -p 3307:3306 -p 81:80 -it \
-e "container=docker"  -v /sys/fs/cgroup:/sys/fs/cgroup  \
 --name centos centos:latest /usr/sbin/init
yum install gcc-c++ pcre-devel zlib-devel make wget openssl-devel which libxml2-devel unzip libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel  git gperftools-devel -y
yum groupinstall 'Development Tools'
yum install -y initscripts
mkdir /root/src
cd /root/src
wget http://nginx.org/download/nginx-1.13.1.tar.gz
tar -xvf nginx-1.13.1.tar.gz
cd nginx-1.13.1
git clone https://github.com/nginx/njs.git
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
git clone http://luajit.org/git/luajit-2.0.git
cd luajit-2.0
make
make install
cd ..
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.6.tar.gz
gunzip v0.9.6.tar.gz
tar -xvf v0.9.6.tar.tar
wget https://luajit.org/download/LuaJIT-2.0.4.zip
unzip LuaJIT-2.0.4.zip
cd LuaJIT-2.0.4
make
make install
cd ..
git clone https://github.com/openssl/openssl.git
cd openssl
git checkout OpenSSL_1_0_2h
cd ..
wget https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz
tar -xvf latest-stable.tar.gz
cd ngx_pagespeed-latest-stable/
wget https://dl.google.com/dl/page-speed/psol/1.11.33.4.tar.gz
tar -xzvf 1.11.33.4.tar.gz
cd ..
git clone https://github.com/openresty/lua-nginx-module.git
git clone https://github.com/simpl/ngx_devel_kit.git

Строим

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=njs/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'  --add-dynamic-module=ngx_http_substitutions_filter_module  --add-module=lua-nginx-module --add-module=ngx_pagespeed-latest-stable --with-openssl=openssl --add-module=ngx_devel_kit
mkdir -p /var/cache/nginx/client_temp
useradd nginx

Добавляем скрипт старта

nano /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -n "$user" ]; then
      if [ -z "`grep $user /etc/passwd`" ]; then
         useradd -M -s /bin/nologin $user
      fi
      options=`$nginx -V 2>&1 | grep 'configure arguments:'`
      for opt in $options; do
          if [ `echo $opt | grep '.*-temp-path'` ]; then
              value=`echo $opt | cut -d "=" -f 2`
              if [ ! -d "$value" ]; then
                  # echo "creating" $value
                  mkdir -p $value && chown -R $user $value
              fi
          fi
       done
    fi
}
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
force_reload() {
    restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
/etc/init.d/nginx

Выходи из докера

Коммитим его

docker commit 1db8f974c6b0 centos:nginx

Теперь у нас образ centos:nginx
Запускаем повторно

docker run --privileged -d --restart always -p 3307:3306 -p 81:80 -it \
-e "container=docker"  -v /sys/fs/cgroup:/sys/fs/cgroup  \
 --name centos centos:nginx /usr/sbin/init

Готово

Добавить комментарий

Войти с помощью: 

Ваш адрес email не будет опубликован. Обязательные поля помечены *

 

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.