docker:構建nginx+php-fpm鏡像(一):構建nginx自啟動鏡像,nginxphp-fpm
步驟一:手動安裝nginx環境,並記錄全過程:#使用yum更新系統yum -y update #下面編譯安裝tengine,查看有哪些包需要安裝#安裝wget包,用於擷取安裝軟體包yum -y install wget cd /usr/local/src#下載nginx安裝包,並指定放置目錄/usr/local/srcwget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz -P /usr/local/src/#z匹配.gz x解壓 f本地tar -zxf tengine-2.1.2.tar.gz #建立nginx需要的使用者和組groupadd -r nginxuseradd -g nginx -M nginx #tengine初次編譯./configure --prefix=/usr/local/tengine \--user=nginx --group=nginx #報錯以及補充系統包:yum -y install gcc pcre-devel openssl-devel #初次編譯通過,增加nginx模組配置再次編譯:--with-http_realip_module #nginx擷取用戶端真實IP的模組--with-http_sub_module #用於替換網站頁面關鍵字--平常基本沒啥用--with-http_gzip_static_module #靜態緩衝壓縮,用於減少流量--with-http_gunzip_module #為不支援gzip模組的用戶端提供解壓縮服務,用於節省空間的減少IO--with-http_ssl_module #使nginx支援https--with-pcre #nginx支援pcre正則,主要是支援rewrite功能--with-http_stub_status_module #用於監控nginx狀態 完整編譯命令如下:
./configure --prefix=/usr/local/tengine \--user=nginx --group=nginx \--with-http_realip_module \--with-http_gzip_static_module \--with-http_gunzip_module \--with-pcre \--with-http_stub_status_module \--with-http_ssl_module
#編譯安裝make & make install #啟動nginx/usr/local/tengine/sbin/nginx 步驟二:根據以上步驟構建dockerfile產生nginx鏡像Dockerfile
####################################################Dockerfile to build mysqlDB container images#base on centos####################################################Set the base image to Centos6FROM centos:6#File SuthorMAINTAINER liujian@wanbu.com.cn #install basic rpmRUN yum -y updateRUN yum -y install wget gcc pcre-devel openssl-develRUN wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz -P /usr/local/src/ \&& groupadd -r nginx && useradd -g nginx -M nginxRUN cd /usr/local/src/ \&& tar -zxf tengine-2.1.2.tar.gz \&& cd tengine-2.1.2/ \&& ./configure --prefix=/usr/local/tengine --user=nginx --group=nginx --with-http_realip_module --with-http_gzip_static_module --with-http_gunzip_module --with-pcre --with-http_stub_status_module --with-http_ssl_module \&& make && make install \&& ln -s /usr/local/tengine/sbin/nginx /usr/sbin/nginx \&& yum -y remove wget gcc pcre-devel openssl-develADD nginx.conf /usr/local/tengine/conf/EXPOSE 80CMD ["nginx","-g","deamon off;"]
#制定Dokcerfile構建nginx鏡像docker build -t nginx_test:v1.0 . #使用鏡像建立容器,測試nginx運行情況docker run -itd -p 0.0.0.0:7788:80 --name nginx_image_test nginx_test:v1.0 #訪問正常,但是nginx設定檔無法修改,只能啟動運行。如果在測試環境需要修改設定檔重啟等,可以使用:#將dockerfile內部CMD ["nginx","-g","deamon off;"]替換為ENTRYPOINT /usr/sbin/nginx -c /etc/nginx/nginx.conf && /bin/bash