docker映象製作 centos6 nginx1.15.6 with NGINX_UPSYNC_MODULE
阿新 • • 發佈:2018-12-12
首先我選擇了在centos6裡部署nginx的映象,如果大家選擇的是centos7,自己重新修改吧
這裡的問題點有幾個:
1,make的版本選擇,因為我下載了最新的cmake,需要c++11編譯
這玩意的安裝比較麻煩,在前面一篇隨筆裡已經寫過gcc在centos裡的安裝
2,docker容器的層級,我使用了 以下辦法來減少層級,不在同一個層級,有些操作會出現問題哦
RUN ..... \
&& .....
3,CMD和Endpoint的使用,我這裡只用了endpoint,但nginx作為後臺執行,需要額外新增引數
ENTRYPOINT ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
4,除錯,在除錯過程中最好使用“docker run -itd nginx_centos6”,把-itd改為-it,這樣能夠檢視到出錯資訊
5,真正部署時,我使用了dockercompose檔案,可以讓很多引數進行額外的配置
# Version 0.1 FROM centos:6 MAINTAINER kuba [email protected] ENV NGINX_UPSYNC_MODULE_VERSION 2.1.0 ENV CMAKE_VERSION 3.12.4 ENV ZLIB_VERSION 1.2.11 ENV PCRE_VERSION 8.42 ENV OPENSSL_VERSION 1_1_1 ENV NGINX_HTTP_CONCAT_VERSION 1.2.2 ENV GEOIP_VERSION 1.4.8 ENV NGINX_VERSION 1.15.6 RUN mkdir -p /opt/software WORKDIR /opt/software/ RUN yum -y update;yum -y install epel-release wget tar xz unzip make autoconf automake curl curl-devel gcc gcc-c++ gcc-g77 kernel-devel gd gd-devel mlocate \ && yum -y install centos-release-scl-rh centos-release-scl \ && yum -y install devtoolset-6-gcc.x86_64 devtoolset-6-gcc-c++.x86_64 \ && yum -y install libtool \ && scl enable devtoolset-6 bash \ && updatedb \ && yum clean all \ && source /opt/rh/devtoolset-6/enable \ && export CC=/opt/rh/devtoolset-6/root/usr/bin/gcc \ && export CXX=/opt/rh/devtoolset-6/root/usr/bin/g++ \ && wget https://github.com/weibocom/nginx-upsync-module/archive/v${NGINX_UPSYNC_MODULE_VERSION}.zip \ && unzip v${NGINX_UPSYNC_MODULE_VERSION}.zip \ && rm -f v${NGINX_UPSYNC_MODULE_VERSION}.zip \ && wget https://github.com/Kitware/CMake/archive/v${CMAKE_VERSION}.zip \ && unzip v${CMAKE_VERSION}.zip \ && rm -f v${CMAKE_VERSION}.zip \ && cd CMake-${CMAKE_VERSION}/ \ && ./bootstrap \ && gmake \ && make install \ && cd ../ \ && wget https://github.com/madler/zlib/archive/v${ZLIB_VERSION}.zip \ && unzip v${ZLIB_VERSION}.zip \ && rm -f v${ZLIB_VERSION}.zip \ && cd zlib-${ZLIB_VERSION}/ \ && ./configure \ && make \ && make install \ && cd ../ \ && wget https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VERSION}.zip \ && unzip pcre-${PCRE_VERSION}.zip \ && rm -f pcre-${PCRE_VERSION}.zip \ && cd pcre-${PCRE_VERSION}/ \ && ./configure --prefix=/usr/local/pcre \ && make \ && make install \ && cd ../ \ && wget https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.zip \ && unzip OpenSSL_${OPENSSL_VERSION}.zip \ && rm -f OpenSSL_${OPENSSL_VERSION}.zip \ && cd openssl-OpenSSL_${OPENSSL_VERSION}/ \ && ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl --shared \ && make \ && make install \ && cd /usr/local/ \ && ln -sf openssl ssl \ && echo "/usr/local/openssl/lib" >>/etc/ld.so.conf \ && ldconfig \ && echo "export OPENSSL=/usr/local/openssl/bin">>/etc/profile \ && echo "export PATH=\$OPENSSL:\$PATH">>/etc/profile \ && source /etc/profile \ && ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl \ && ln -sf /usr/local/openssl/include/openssl /usr/include/openssl \ && ln -sf /usr/local/openssl/lib/libcrypto.so.1.1 /lib/libcrypto.so.6 \ && ldconfig -v \ && cd /opt/software/ \ && wget https://github.com/alibaba/nginx-http-concat/archive/${NGINX_HTTP_CONCAT_VERSION}.zip \ && unzip ${NGINX_HTTP_CONCAT_VERSION}.zip \ && rm -f ${NGINX_HTTP_CONCAT_VERSION}.zip \ && wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz \ && tar zxvf GeoIP.tar.gz \ && rm -f GeoIP.tar.gz \ && cd GeoIP-${GEOIP_VERSION}/ \ && ./configure \ && make \ && make install \ && updatedb \ && locate libGeoIP.so.1 \ && echo "/usr/local/lib" >> /etc/ld.so.conf \ && ldconfig \ && cd ../ \ && wget https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}.zip \ && unzip release-${NGINX_VERSION}.zip \ && rm -f release-${NGINX_VERSION}.zip \ && groupadd www \ && useradd -g www www -s /bin/false \ && cd nginx-release-${NGINX_VERSION}/ \ && ./auto/configure --prefix=/usr/local/nginx --user=www --group=www --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --without-http_memcached_module --with-http_ssl_module --with-openssl=/opt/software/openssl-OpenSSL_${OPENSSL_VERSION}/ --with-http_realip_module --with-http_image_filter_module --with-http_mp4_module --with-http_flv_module --with-pcre=/opt/software/pcre-${PCRE_VERSION}/ --with-zlib=/opt/software/zlib-${ZLIB_VERSION}/ --with-http_addition_module --with-http_geoip_module --with-http_sub_module --with-http_degradation_module --add-module=/opt/software/nginx-upsync-module-${NGINX_UPSYNC_MODULE_VERSION}/ --add-module=/opt/software/nginx-http-concat-${NGINX_HTTP_CONCAT_VERSION}/ \ && make \ && make install ADD ./nginx.conf /usr/local/nginx/conf/ ADD ./html/ /usr/local/nginx/html/ ENTRYPOINT ["/usr/local/nginx/sbin/nginx","-g","daemon off;"] EXPOSE 80 443
nginx.conf
user www www; worker_processes 4; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 8096; multi_accept on; use epoll; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; client_max_body_size 10M; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; error_page 404 /errors/404.html; error_page 500 502 503 504 /errors/50x.html; location ^~ /errors/ { root html; } location / { root html; index index.html index.htm; } } }
建立映象
docker build -t nginx_centos6 ./
啟動映象
docker run -it nginx_centos6
這樣啟動後,正常來說使用http://127.0.0.1是訪問拒絕的,因為Docker裡有自己的IP,需要隱射一下
我選擇使用了docker_compose來配置隱射
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: '2' services: nginx0: image: nginx_centos6 restart: always container_name: nginx0 ports: - 80:80
執行docker-compose -f docker-compose-nginx.yaml up -d 2>&1
一切OK